Skip to content

Commit

Permalink
Merge pull request #28 from hpicgs/dev
Browse files Browse the repository at this point in the history
Next minor release 0.5.0
  • Loading branch information
Jasperhino authored Sep 20, 2022
2 parents f6b27e0 + 745ed4b commit 5f5f162
Show file tree
Hide file tree
Showing 36 changed files with 853 additions and 214 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,17 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 16
cache: 'pnpm'
cache: "pnpm"
cache-dependency-path: frontend/pnpm-lock.yaml

- name: Install treemaps library 📦
run: |
cd frontend
git clone --branch hiviser_deployment https://${{ secrets.SEERENE_TREEMAPS_DEPLOY_USER }}:${{ secrets.SEERENE_TREEMAPS_DEPLOY_TOKEN }}@gitlab.hpi3d.de/seerene/treemaps.git
cd treemaps
npm i
npm run build-lib
- name: Install and Build 🔧
run: |
cd frontend
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,6 @@ $RECYCLE.BIN/
# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)

node_modules

metrics.json
metrics.csv
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "frontend/treemaps"]
path = frontend/treemaps
url = [email protected]:seerene/treemaps.git
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"command": "npm start",
"cwd": "${workspaceFolder}/analytics",
"name": "Run npm start",
"request": "launch",
"type": "node-terminal"
}
]
}
19 changes: 2 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Check out Git repository
uses: actions/checkout@v3

- name: Run linters
- name: Run Hiviser Action
uses: hpicgs/hiviser-action@v0
# Optional, use if you want to analyse a specific folder
with:
Expand Down Expand Up @@ -70,22 +70,7 @@ pnpm start
```
### Git blobs gh api
gh api -H "Accept: application/vnd.github.v3+json" /repos/hpicgs/github-software-analytics-embedding/git/matching-refs/notes/commits
gh api -H "Accept: application/vnd.github.v3+json" /repos/hpicgs/github-software-analytics-embedding/git/commits/1ff88b0dc996214148b5b98669f52cd876ea9e4a
gh api --method POST -H "Accept: application/vnd.github.v3+json" /repos/hpicgs/github-software-analytics-embedding/git/blobs -f content='My metrics blob' -f encoding='utf-8'
Get the blob
```
gh api -H "Accept: application/vnd.github.v3+json" /repos/hpicgs/github-software-analytics-embedding/git/blobs/a7553cd0a3c0f65602eb761017063c01558b4b91
```
#### Curl
curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/hpicgs/github-software-analytics-embedding/git/blobs/a7553cd0a3c0f65602eb761017063c01558b4b91
curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/hpicgs/github-software-analytics-embedding/git/blobs/a7553cd0a3c0f65602eb761017063c01558b4b91 | jq -r '.content' | base64 --decode
This repo uses the github git database API to store commit based software analytics data on a custom ref directly in the repository. This means the meta data will not be cloned if you run git pull normally.
## Building and running the docker container locally
```
Expand Down
3 changes: 3 additions & 0 deletions analytics/metrics.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
filename,LoC,NoC,CLoC, DC, Number of Functions
../testrepo/test1.ts,17,1,1,0.05555555555555555,0
../testrepo/testfolder/test2.ts,9,3,3,0.25,0
12 changes: 6 additions & 6 deletions analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"description": "Seminar Project of the Seminar \"Advanced Techniques for Analysis and Visualization of Software Data\" of CGS, HPI and DEF in the Summer Term 2022",
"scripts": {
"start": "cross-env REPOSITORY_PATH=../testrepo ts-node src/index.ts",
"debug": "cross-env DEBUG=True REPOSITORY_PATH=../testrepo ts-node src/index.ts",
"build": "tsc"
},
},
"repository": {
"type": "git",
"url": "git+https://github.com/hpicgs/github-software-analytics-embedding.git"
Expand All @@ -16,22 +17,21 @@
"homepage": "https://github.com/hpicgs/github-software-analytics-embedding#readme",
"dependencies": {
"@octokit/auth-action": "^1.3.3",
"csv-writer": "^1.6.0",
"dotenv": "^16.0.1",
"esprima": "^4.0.1",
"glob": "^8.0.3",
"octokit": "^1.8.1"
"octokit": "^1.8.1",
"typescript": "^4.7.3"
},
"devDependencies": {
"@octokit/types": "^6.38.1",
"@tsconfig/node16": "^1.0.2",
"@types/esprima": "^4.0.3",
"@types/glob": "^7.2.0",
"@types/node": "^17.0.36",
"@typescript-eslint/eslint-plugin": "^5.26.0",
"@typescript-eslint/parser": "^5.26.0",
"cross-env": "^7.0.3",
"eslint": "^8.16.0",
"ts-node": "^10.8.0",
"typescript": "^4.7.3"
"ts-node": "^10.8.0"
}
}
21 changes: 7 additions & 14 deletions analytics/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 26 additions & 16 deletions analytics/src/github/api.ts → analytics/src/github.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import { Octokit } from "octokit";
import { createActionAuth } from "@octokit/auth-action"
import { createActionAuth } from "@octokit/auth-action";
import "dotenv/config";

if (!process.env.GITHUB_REPOSITORY)
throw new Error("GITHUB_REPOSITORY environment variable is not set");

const repo_path = process.env.GITHUB_REPOSITORY;
const [owner, repo] = repo_path.split('/');
const [owner, repo] = repo_path.split("/");
const commit_sha = process.env.GITHUB_SHA || "default_tag";

let octokit: Octokit;
if (process.env.GITHUB_ACTIONS) {
console.log("Running in GitHub Actions, using @octokit/auth-action");
octokit = new Octokit({ authStrategy: createActionAuth});
octokit = new Octokit({ authStrategy: createActionAuth });
} else {
if (!process.env.GITHUB_TOKEN)
throw new Error("GITHUB_TOKEN environment variable is not set. This needs to be set if you want to run this script outside of GitHub Actions");
throw new Error(
"GITHUB_TOKEN environment variable is not set. This needs to be set if you want to run this script outside of GitHub Actions"
);
octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });
}

Expand Down Expand Up @@ -46,15 +48,13 @@ async function createRef(ref: string, sha: string) {
owner,
repo,
ref,
sha
sha,
}
);

console.log(response);
}



async function createBlob(content: string) {
console.log(`creating blob with content: ${content.substring(0, 10)} ...`);

Expand All @@ -71,11 +71,8 @@ async function createBlob(content: string) {
console.log(response);
}

async function createTree(content: string): Promise<string> {
console.log(
`creating tree at ${owner}/${repo} with content:
${content.substring(0, 10)}...`
);
async function createTree(csv: string, json: string): Promise<string> {
console.log(`creating tree at ${owner}/${repo}`);

const response = await octokit.request(
`POST /repos/${owner}/${repo}/git/trees`,
Expand All @@ -87,7 +84,13 @@ async function createTree(content: string): Promise<string> {
path: "metrics.csv",
mode: "100644",
type: "blob",
content,
content: csv,
},
{
path: "metrics.json",
mode: "100644",
type: "blob",
content: json,
},
],
}
Expand All @@ -97,8 +100,15 @@ async function createTree(content: string): Promise<string> {
return response.data.sha;
}

export async function saveMetrics(metrics_csv: string) {
//Todo: add the image to this call later
const tree_sha = await createTree(metrics_csv);
export async function storeMetricsToRepo(
metrics_csv: string,
metrics_json: string
) {
if (process.env.DEBUG) {
console.log("DEBUG mode enabled, skipping GitHub API calls");
return;
}

const tree_sha = await createTree(metrics_csv, metrics_json);
await createRef(`refs/metrics/${commit_sha}`, tree_sha);
}
Loading

0 comments on commit 5f5f162

Please sign in to comment.