Skip to content
This repository has been archived by the owner on Apr 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1499 from DashboardHub/v0.11.6
Browse files Browse the repository at this point in the history
Deploy to production
  • Loading branch information
eddiejaoude committed Sep 12, 2019
2 parents 00c4d2d + d1ce327 commit 59d75ed
Show file tree
Hide file tree
Showing 70 changed files with 2,337 additions and 324 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Please get in touch via [@DashboardHub](https://twitter.com/DashboardHub) and le
2. Enter the 2 OAuth private keys from GitHub into the Firebase Authentication
3. Click **Databases** and create an empty `firestore` database (indexes, security, collections and rules will all be automatically created later on as part of the deployment)
4. Update `{{ FIREBASE_FUNCTIONS_URL }}` in file `functions/src/environments/environment.ts` with your function subdomain, for example `us-central1-pipelinedashboard-test`
4. Update `{{ GITHUB_WEBHOOK_SECRET }}` in file `functions/src/environments/environment.ts` with your private secret key (random string), this is used to protect your webhook function, for example `pipelinedashboard-test-123`

#### Angular

Expand Down
21 changes: 15 additions & 6 deletions functions/package-lock.json

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

3 changes: 2 additions & 1 deletion functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
"firebase-functions": "^3.1.0",
"request": "^2.88.0",
"request-promise-native": "^1.0.7",
"uuid": "^3.3.2",
"uuid": "^3.3.3",
"winston": "^3.2.1"
},
"devDependencies": {
"@types/cors": "^2.8.5",
"@types/request-promise-native": "^1.0.16",
"@types/uuid": "3.4.3",
"firebase-functions-test": "^0.1.6",
"tslint": "~5.16.0",
"typescript": "^3.4.5"
Expand Down
8 changes: 8 additions & 0 deletions functions/src/client/firebase-admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ export declare type WriteResult = admin.firestore.WriteResult;
export declare type QuerySnapshot = admin.firestore.QuerySnapshot;
export declare type QueryDocumentSnapshot = admin.firestore.QueryDocumentSnapshot;
export declare type DocumentReference = admin.firestore.DocumentReference;
export declare type Transaction = admin.firestore.Transaction;
export declare type WriteBatch = admin.firestore.WriteBatch;
export declare type FieldValue = admin.firestore.FieldValue;
export declare type CollectionReference = admin.firestore.CollectionReference;
export declare type Query = admin.firestore.Query;

// tslint:disable-next-line: typedef
export const FieldPath = admin.firestore.FieldPath;

export const IncrementFieldValue: FieldValue = admin.firestore.FieldValue.increment(1);

56 changes: 55 additions & 1 deletion functions/src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,60 @@
export const enviroment: Config = {
githubWebhook: {
url: 'https://{{ FIREBASE_FUNCTIONS_URL }}.cloudfunctions.net/responseGitWebhookRepository',
secret: '{{ GITHUB_WEBHOOK_SECRET }}',
content_type: 'json',
insecure_ssl: '0',
events: [
'push',
// IMPLEMENTED
'create',
'issue_comment',
'issues',
'member',
'milestone',
'pull_request',
'push',
'release',
'repository',
'status',
'watch',

// NOT IMPLEMENTED
'check_run',
'check_suite',
'commit_comment',
'delete',
'deploy_key',
'deployment',
'deployment_status',
'fork',
'gollum',
'label',
'meta',
'page_build',
'project_card',
'project_column',
'project',
'public',
'pull_request_review',
'pull_request_review_comment',
'registry_package',
'repository_import',
'repository_vulnerability_alert',
'star',
'team_add',

// NOT ALLOW for this hook
// 'content_reference',
// 'github_app_authorization',
// 'installation',
// 'installation_repositories',
// 'marketplace_purchase',
// 'membership',
// 'organization',
// 'org_block',
// 'repository_dispatch',
// 'security_advisory',
// 'team',
],
},

Expand All @@ -13,6 +64,9 @@ export const enviroment: Config = {
interface Config {
githubWebhook: {
url: string,
secret: string,
content_type: 'json' | 'form',
insecure_ssl: '0' | '1',
events: string[],
}
}
25 changes: 14 additions & 11 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@ import { onResponseGitWebhookRepository } from './repository/response-git-webhoo
import { onUpdateRepository } from './repository/update-repository';

// Dashboard users
import { onCreateUser } from './user/create-user';
import { getUserEvents, EventsInput } from './user/events';
import { getUserRepos, ReposInput } from './user/repos';
import { onUpdateUserStats } from './user/stats';
import { onUpdateUser } from './user/update-user';

// Dashboard projects
import { deleteMonitorPings, ping, MonitorInfoInput } from './monitor/monitor';
import { onDeleteProject, onDeleteProjectRepositories } from './project/delete-project';
import { onUpdateProjectRepositories } from './project/update-repositories';
import { onDeleteProject } from './project/delete-project';
import { onUpdateProject } from './project/update-project';
import { onDeleteGitWebhookRepository, DeleteGitWebhookRepositoryInput } from './repository/delete-git-webhook-repository';

import { onCreatePings, onCreateProject, onCreateUser } from './application/stats';
import { onCreatePings as onCreatePingsStats, onCreateProject as onCreateProjectStats, onCreateUser as onCreateUserStats } from './application/stats';
import { updateViews, ProjectInput } from './project/project';
import { deletePingsAfter30days, runAllMonitors60Mins } from './scheduler/schedule';

Expand All @@ -34,23 +36,24 @@ declare type Change<T> = functions.Change<T>;

export const findAllUserRepositories: HttpsFunction = functions.https.onCall((input: ReposInput, context: CallableContext) => getUserRepos(input.token, context.auth.uid));
export const findAllUserEvents: HttpsFunction = functions.https.onCall((input: EventsInput, context: CallableContext) => getUserEvents(input.token, context.auth.uid, input.username));
export const findRepositoryInfo: HttpsFunction = functions.https.onCall((input: RepositoryInfoInput, context: CallableContext) => getRepositoryInfo(input.token, input.fullName));
export const findRepositoryInfo: HttpsFunction = functions.https.onCall((input: RepositoryInfoInput, context: CallableContext) => getRepositoryInfo(input.token, input.repository));
export const createGitWebhookRepository: HttpsFunction = functions.https.onCall((input: CreateGitWebhookRepositoryInput, context: CallableContext) => onCreateGitWebhookRepository(input.token, input.repositoryUid));
export const deleteGitWebhookRepository: HttpsFunction = functions.https.onCall((input: DeleteGitWebhookRepositoryInput, context: CallableContext) => onDeleteGitWebhookRepository(input.token, input.repositoryUid));
export const deleteGitWebhookRepository: HttpsFunction = functions.https.onCall((input: DeleteGitWebhookRepositoryInput, context: CallableContext) => onDeleteGitWebhookRepository(input.token, input.data));
export const responseGitWebhookRepository: HttpsFunction = onResponseGitWebhookRepository;
export const pingMonitor: HttpsFunction = functions.https.onCall((input: MonitorInfoInput, context: CallableContext) => ping(input.projectUid, input.monitorUid, input.type));
export const deletePingsByMonitor: HttpsFunction = functions.https.onCall((input: MonitorInfoInput, context: CallableContext) => deleteMonitorPings(input.projectUid, input.monitorUid));
export const updateProjectViews: HttpsFunction = functions.https.onCall((input: ProjectInput, context: CallableContext) => updateViews(input.projectUid));

export const deletePingsByProject: CloudFunction<DocumentSnapshot> = onDeleteProject;
export const deleteProjectRepositories: CloudFunction<DocumentSnapshot> = onDeleteProjectRepositories;
export const updateProjectRepositories: CloudFunction<DocumentSnapshot> = onUpdateProjectRepositories;
export const deleteProject: CloudFunction<DocumentSnapshot> = onDeleteProject;
export const updateProject: CloudFunction<DocumentSnapshot> = onUpdateProject;
export const updateRepository: CloudFunction<Change<DocumentSnapshot>> = onUpdateRepository;
export const createRepository: CloudFunction<DocumentSnapshot> = onCreateRepository;
export const updateUserStats: CloudFunction<DocumentSnapshot> = onUpdateUserStats;
export const delete30DaysPings: CloudFunction<DocumentSnapshot> = deletePingsAfter30days;
export const runPings60Mins: CloudFunction<DocumentSnapshot> = runAllMonitors60Mins;

export const createProject: CloudFunction<DocumentSnapshot> = onCreateProject;
export const createPing: CloudFunction<DocumentSnapshot> = onCreatePings;
export const createUser: CloudFunction<DocumentSnapshot> = onCreateUser;
export const updateUser: CloudFunction<Change<DocumentSnapshot>> = onUpdateUser;

export const createProjectStat: CloudFunction<DocumentSnapshot> = onCreateProjectStats;
export const createPingsStats: CloudFunction<DocumentSnapshot> = onCreatePingsStats;
export const createUserStats: CloudFunction<DocumentSnapshot> = onCreateUserStats;
13 changes: 6 additions & 7 deletions functions/src/mappers/github/event.mapper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Third party modules
import { firestore } from 'firebase-admin';

// Dashboard hub firebase functions mappers/modesl
// Dashboard mappers/models
import { GitHubEventType } from './event.mapper';
import { GitHubOrganisationtInput, GitHubOrganisationMapper, GitHubOrganisationModel } from './organisation.mapper';
import { GitHubPayloadInput, GitHubPayloadMapper, GitHubPayloadModel } from './payload.mapper';
Expand All @@ -13,18 +12,18 @@ export type GitHubEventType = 'PullRequestEvent' | 'IssueCommentEvent' | 'Create
export interface GitHubEventInput {
id: string;
type: GitHubEventType;
public: string;
public: boolean;
actor: GitHubUserInput;
repo: GitHubRepositoryInput;
org: GitHubOrganisationtInput;
payload: GitHubPayloadInput;
created_at: firestore.Timestamp;
created_at: string;
}

export interface GitHubEventModel {
uid: string;
uid?: string;
type: GitHubEventType;
public: string;
public: boolean;
actor: GitHubUserModel;
repository: GitHubRepositoryModel;
organisation?: GitHubOrganisationModel;
Expand All @@ -41,7 +40,7 @@ export class GitHubEventMapper {
actor: GitHubUserMapper.import(input.actor),
repository: GitHubRepositoryMapper.import(input.repo, 'event'),
payload: GitHubPayloadMapper.import(input.type, input.payload),
createdOn: input.created_at,
createdOn: firestore.Timestamp.fromDate(new Date(input.created_at)),
};

if (input.org) {
Expand Down
15 changes: 7 additions & 8 deletions functions/src/mappers/github/issue.mapper.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
// Third party modules
import { firestore } from 'firebase-admin';

// Dashboard hub firebase functions mappers/models
// Dashboard mappers/models
import { GitHubUserInput, GitHubUserMapper, GitHubUserModel } from './user.mapper';

export interface GitHubIssueInput {
id: string;
id: number;
html_url: string;
state: string;
title: string;
number: number;
body: string;
user: GitHubUserInput;
assignees: GitHubUserInput[];
created_at: firestore.Timestamp;
updated_at: firestore.Timestamp;
created_at: string;
updated_at: string;
}

export interface GitHubIssueModel {
uid: string;
uid: number;
url: string;
state: string;
title: string;
Expand All @@ -41,8 +40,8 @@ export class GitHubIssueMapper {
description: input.body,
owner: GitHubUserMapper.import(input.user),
assignees: input.assignees.map((assignee: GitHubUserInput) => GitHubUserMapper.import(assignee)),
createdOn: input.created_at,
updatedOn: input.updated_at,
createdOn: firestore.Timestamp.fromDate(new Date(input.created_at)),
updatedOn: firestore.Timestamp.fromDate(new Date(input.updated_at)),
};
}
}
10 changes: 8 additions & 2 deletions functions/src/mappers/github/milestone.mapper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { firestore } from 'firebase-admin';

// Dashboard mappers/models
import { GitHubUserInput, GitHubUserMapper, GitHubUserModel } from './index.mapper';

export interface GitHubMilestoneInput {
id: number;
title: string;
creator: GitHubUserInput;
state: string;
Expand All @@ -12,27 +16,29 @@ export interface GitHubMilestoneInput {
}

export interface GitHubMilestoneModel {
uid: number;
title: string;
creator: GitHubUserModel;
state: string;
openIssues: number;
closeIssues: number;
htmlUrl: string;
description: string;
updatedAt: string;
updatedAt: firestore.Timestamp;
}

export class GitHubMilestoneMapper {
static import(input: GitHubMilestoneInput): GitHubMilestoneModel {
return {
uid: input.id,
title: input.title,
creator: GitHubUserMapper.import(input.creator),
state: input.state,
openIssues: input.open_issues,
closeIssues: input.closed_issues,
htmlUrl: input.html_url,
description: input.description,
updatedAt: input.updated_at,
updatedAt: firestore.Timestamp.fromDate(new Date(input.updated_at)),
};
}
}
8 changes: 5 additions & 3 deletions functions/src/mappers/github/payload.mapper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GitHubEventType } from './event.mapper';

export interface GitHubPayloadInput {
title: string;
title?: string;
action?: string;
ref?: string;
ref_type?: string;
Expand All @@ -15,7 +15,9 @@ export interface GitHubPayloadInput {
body: string;
};
release?: {
name: string;
tag_name: string;
target_commitish: string;
name?: string;
};
}

Expand Down Expand Up @@ -47,7 +49,7 @@ export class GitHubPayloadMapper {
output.title = `${input.ref_type}: ${input.ref}`;
break;
case 'ReleaseEvent':
output.title = `${input.action}: ${input.release.name}`;
output.title = `${input.action}: ${input.release.tag_name}@${input.release.target_commitish}` + (input.release.name ? ` - ${input.release.name}` : '');
break;
case 'WatchEvent':
output.title = `${input.action} watching`;
Expand Down
Loading

0 comments on commit 59d75ed

Please sign in to comment.