Skip to content

Commit

Permalink
Fix github release status key and tag
Browse files Browse the repository at this point in the history
  • Loading branch information
rick-nu committed Mar 21, 2022
1 parent 0ac32d6 commit 5159f85
Show file tree
Hide file tree
Showing 23 changed files with 4,897 additions and 16 deletions.
2 changes: 1 addition & 1 deletion backend/parser/github/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const getBranch = (reference: string): string | null => {

export const getTag = (reference: string): string | null => {
if (reference.includes('refs/tags')) {
reference.replace('refs/tags/', '');
return reference.replace('refs/tags/', '');
}

return null;
Expand Down
19 changes: 5 additions & 14 deletions backend/parser/github/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { getBranch, getTag } from 'backend/parser/github/helper';
import Slugify from 'backend/parser/slug';
import { GitHubPush, GitHubWorkflowJob, GitHubWorkflowRun } from 'types/github';
import Status from 'types/status';
Expand All @@ -8,32 +7,24 @@ import GitHubPushParser from './push';
import GitHubRunParser from './run';

class GitLabParser {
getInternalId(projectId: number, repositoryName: string, branch: string | null, tag: string | null): string {
let id = `github-${projectId}-${Slugify(repositoryName)}`;
getInternalId(projectId: number, repositoryName: string, uniqueElement: string): string {
const base = `github-${projectId}-${Slugify(repositoryName)}`;

if (branch) {
id += `-${Slugify(branch)}`;
}

if (tag) {
id += `-${Slugify(tag)}`;
}

return id;
return `${base}-${Slugify(uniqueElement.replace('refs/tags/', '').replace('refs/heads/', ''))}`;
}

parsePush(push: GitHubPush): Status {
console.log('[parser/github] Parsing push...');

const id = this.getInternalId(push.repository.id, push.repository.name, getBranch(push.ref), getTag(push.ref));
const id = this.getInternalId(push.repository.id, push.repository.name, push.ref);

return GitHubPushParser.parsePush(id, push);
}

parseWorkflowRun(run: GitHubWorkflowRun): Status {
console.log('[parser/github] Parsing workflow run...');

const id = this.getInternalId(run.repository.id, run.repository.name, run.workflow_run.head_branch, null);
const id = this.getInternalId(run.repository.id, run.repository.name, run.workflow_run.head_branch);

return GitHubRunParser.parseRun(id, run);
}
Expand Down
2 changes: 2 additions & 0 deletions backend/parser/github/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ class GitHubPushParser {
};

const branch = getBranch(push.ref);
console.log(`=== BRANCH ${branch} ===`);
if (branch) {
status.branch = branch;
}

const tag = getTag(push.ref);
console.log(`=== TAG ${tag} ===`);
if (tag) {
status.tag = tag;
}
Expand Down
14 changes: 13 additions & 1 deletion backend/router/route/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,19 @@ import ReadTheDocsRouter from './webhook/readthedocs';
const router = express.Router();

const cleanHeaders = (headers: IncomingHttpHeaders): IncomingHttpHeaders => {
const headersToClean = ['x-gitlab-event-uuid', 'connection', 'host', 'content-length'];
const headersToClean = [
'x-gitlab-event-uuid',
'connection',
'host',
'content-length',
'accept',
'x-github-delivery',
'x-github-hook-id',
'x-github-hook-installation-target-id',
'x-github-hook-installation-target-type',
'x-hub-signature',
'x-hub-signature-256',
];

for (let headerToClean of headersToClean) {
delete headers[headerToClean];
Expand Down
204 changes: 204 additions & 0 deletions cypress/fixtures/github/release/1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
{
"headers": {
"user-agent": "GitHub-Hookshot/a945deb",
"accept": "*/*",
"x-github-delivery": "b51da720-a950-11ec-90a5-aad9667c04c6",
"x-github-event": "release",
"x-github-hook-id": "346531167",
"x-github-hook-installation-target-id": "56302138",
"x-github-hook-installation-target-type": "repository",
"x-hub-signature": "sha1=73f4a5b6a950d16b3e22551a2bbe66820a556c61",
"x-hub-signature-256": "sha256=2839057eed94400a7e5d629eb18d5ca429017f1db0e2b7ba9adf2d271cb0ec8c",
"content-type": "application/json"
},
"body": {
"action": "prereleased",
"release": {
"url": "https://api.github.com/repos/CIMonitor/CIMonitor/releases/62369063",
"assets_url": "https://api.github.com/repos/CIMonitor/CIMonitor/releases/62369063/assets",
"upload_url": "https://uploads.github.com/repos/CIMonitor/CIMonitor/releases/62369063/assets{?name,label}",
"html_url": "https://github.com/CIMonitor/CIMonitor/releases/tag/4.0.0-rc.1",
"id": 62369063,
"author": {
"login": "RickvdStaaij",
"id": 6495166,
"node_id": "MDQ6VXNlcjY0OTUxNjY=",
"avatar_url": "https://avatars.githubusercontent.com/u/6495166?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/RickvdStaaij",
"html_url": "https://github.com/RickvdStaaij",
"followers_url": "https://api.github.com/users/RickvdStaaij/followers",
"following_url": "https://api.github.com/users/RickvdStaaij/following{/other_user}",
"gists_url": "https://api.github.com/users/RickvdStaaij/gists{/gist_id}",
"starred_url": "https://api.github.com/users/RickvdStaaij/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/RickvdStaaij/subscriptions",
"organizations_url": "https://api.github.com/users/RickvdStaaij/orgs",
"repos_url": "https://api.github.com/users/RickvdStaaij/repos",
"events_url": "https://api.github.com/users/RickvdStaaij/events{/privacy}",
"received_events_url": "https://api.github.com/users/RickvdStaaij/received_events",
"type": "User",
"site_admin": false
},
"node_id": "RE_kwDOA1saOs4Dt60n",
"tag_name": "4.0.0-rc.1",
"target_commitish": "master",
"name": "Version 4.0.0 release candidate 1",
"draft": false,
"prerelease": true,
"created_at": "2022-03-21T19:46:28Z",
"published_at": "2022-03-21T19:54:24Z",
"assets": [],
"tarball_url": "https://api.github.com/repos/CIMonitor/CIMonitor/tarball/4.0.0-rc.1",
"zipball_url": "https://api.github.com/repos/CIMonitor/CIMonitor/zipball/4.0.0-rc.1",
"body": "# What\r\n\r\n- Complete rebuild of CIMonitor front- and backend\r\n- Push statuses via webhooks\r\n - GitHub webhook support\r\n - GitLab webhook support\r\n - Read the docs webhook support\r\n- Allow multiple builds/pipelines per status "
},
"repository": {
"id": 56302138,
"node_id": "MDEwOlJlcG9zaXRvcnk1NjMwMjEzOA==",
"name": "CIMonitor",
"full_name": "CIMonitor/CIMonitor",
"private": false,
"owner": {
"login": "CIMonitor",
"id": 18479455,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjE4NDc5NDU1",
"avatar_url": "https://avatars.githubusercontent.com/u/18479455?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/CIMonitor",
"html_url": "https://github.com/CIMonitor",
"followers_url": "https://api.github.com/users/CIMonitor/followers",
"following_url": "https://api.github.com/users/CIMonitor/following{/other_user}",
"gists_url": "https://api.github.com/users/CIMonitor/gists{/gist_id}",
"starred_url": "https://api.github.com/users/CIMonitor/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/CIMonitor/subscriptions",
"organizations_url": "https://api.github.com/users/CIMonitor/orgs",
"repos_url": "https://api.github.com/users/CIMonitor/repos",
"events_url": "https://api.github.com/users/CIMonitor/events{/privacy}",
"received_events_url": "https://api.github.com/users/CIMonitor/received_events",
"type": "Organization",
"site_admin": false
},
"html_url": "https://github.com/CIMonitor/CIMonitor",
"description": "Displays CI statuses on a dashboard and triggers fun modules representing the status!",
"fork": false,
"url": "https://api.github.com/repos/CIMonitor/CIMonitor",
"forks_url": "https://api.github.com/repos/CIMonitor/CIMonitor/forks",
"keys_url": "https://api.github.com/repos/CIMonitor/CIMonitor/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/CIMonitor/CIMonitor/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/CIMonitor/CIMonitor/teams",
"hooks_url": "https://api.github.com/repos/CIMonitor/CIMonitor/hooks",
"issue_events_url": "https://api.github.com/repos/CIMonitor/CIMonitor/issues/events{/number}",
"events_url": "https://api.github.com/repos/CIMonitor/CIMonitor/events",
"assignees_url": "https://api.github.com/repos/CIMonitor/CIMonitor/assignees{/user}",
"branches_url": "https://api.github.com/repos/CIMonitor/CIMonitor/branches{/branch}",
"tags_url": "https://api.github.com/repos/CIMonitor/CIMonitor/tags",
"blobs_url": "https://api.github.com/repos/CIMonitor/CIMonitor/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/CIMonitor/CIMonitor/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/CIMonitor/CIMonitor/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/CIMonitor/CIMonitor/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/CIMonitor/CIMonitor/statuses/{sha}",
"languages_url": "https://api.github.com/repos/CIMonitor/CIMonitor/languages",
"stargazers_url": "https://api.github.com/repos/CIMonitor/CIMonitor/stargazers",
"contributors_url": "https://api.github.com/repos/CIMonitor/CIMonitor/contributors",
"subscribers_url": "https://api.github.com/repos/CIMonitor/CIMonitor/subscribers",
"subscription_url": "https://api.github.com/repos/CIMonitor/CIMonitor/subscription",
"commits_url": "https://api.github.com/repos/CIMonitor/CIMonitor/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/CIMonitor/CIMonitor/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/CIMonitor/CIMonitor/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/CIMonitor/CIMonitor/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/CIMonitor/CIMonitor/contents/{+path}",
"compare_url": "https://api.github.com/repos/CIMonitor/CIMonitor/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/CIMonitor/CIMonitor/merges",
"archive_url": "https://api.github.com/repos/CIMonitor/CIMonitor/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/CIMonitor/CIMonitor/downloads",
"issues_url": "https://api.github.com/repos/CIMonitor/CIMonitor/issues{/number}",
"pulls_url": "https://api.github.com/repos/CIMonitor/CIMonitor/pulls{/number}",
"milestones_url": "https://api.github.com/repos/CIMonitor/CIMonitor/milestones{/number}",
"notifications_url": "https://api.github.com/repos/CIMonitor/CIMonitor/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/CIMonitor/CIMonitor/labels{/name}",
"releases_url": "https://api.github.com/repos/CIMonitor/CIMonitor/releases{/id}",
"deployments_url": "https://api.github.com/repos/CIMonitor/CIMonitor/deployments",
"created_at": "2016-04-15T07:57:09Z",
"updated_at": "2022-03-20T08:36:28Z",
"pushed_at": "2022-03-21T19:54:24Z",
"git_url": "git://github.com/CIMonitor/CIMonitor.git",
"ssh_url": "[email protected]:CIMonitor/CIMonitor.git",
"clone_url": "https://github.com/CIMonitor/CIMonitor.git",
"svn_url": "https://github.com/CIMonitor/CIMonitor",
"homepage": "",
"size": 51656,
"stargazers_count": 38,
"watchers_count": 38,
"language": "TypeScript",
"has_issues": true,
"has_projects": true,
"has_downloads": true,
"has_wiki": false,
"has_pages": false,
"forks_count": 11,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 2,
"license": null,
"allow_forking": true,
"is_template": false,
"topics": [
"cd",
"ci",
"ci-status",
"continuous-deployment",
"continuous-integration",
"dashboard",
"github",
"github-actions",
"gitlab",
"gpio",
"hacktoberfest",
"monitoring",
"pipeline",
"raspberry-pi",
"webhooks"
],
"visibility": "public",
"forks": 11,
"open_issues": 2,
"watchers": 38,
"default_branch": "master"
},
"organization": {
"login": "CIMonitor",
"id": 18479455,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjE4NDc5NDU1",
"url": "https://api.github.com/orgs/CIMonitor",
"repos_url": "https://api.github.com/orgs/CIMonitor/repos",
"events_url": "https://api.github.com/orgs/CIMonitor/events",
"hooks_url": "https://api.github.com/orgs/CIMonitor/hooks",
"issues_url": "https://api.github.com/orgs/CIMonitor/issues",
"members_url": "https://api.github.com/orgs/CIMonitor/members{/member}",
"public_members_url": "https://api.github.com/orgs/CIMonitor/public_members{/member}",
"avatar_url": "https://avatars.githubusercontent.com/u/18479455?v=4",
"description": "Monitor your CI builds and deployments, with some epic additions."
},
"sender": {
"login": "RickvdStaaij",
"id": 6495166,
"node_id": "MDQ6VXNlcjY0OTUxNjY=",
"avatar_url": "https://avatars.githubusercontent.com/u/6495166?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/RickvdStaaij",
"html_url": "https://github.com/RickvdStaaij",
"followers_url": "https://api.github.com/users/RickvdStaaij/followers",
"following_url": "https://api.github.com/users/RickvdStaaij/following{/other_user}",
"gists_url": "https://api.github.com/users/RickvdStaaij/gists{/gist_id}",
"starred_url": "https://api.github.com/users/RickvdStaaij/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/RickvdStaaij/subscriptions",
"organizations_url": "https://api.github.com/users/RickvdStaaij/orgs",
"repos_url": "https://api.github.com/users/RickvdStaaij/repos",
"events_url": "https://api.github.com/users/RickvdStaaij/events{/privacy}",
"received_events_url": "https://api.github.com/users/RickvdStaaij/received_events",
"type": "User",
"site_admin": false
}
}
}
Loading

0 comments on commit 5159f85

Please sign in to comment.