chore: update dashboard functions (#9504)

* Updates the package dependencies of the Dashboard dependencies. There seem to be errors with the old `node-github` API, but updating to the latest version (`@octokit/rest`) seems to work locally.
This commit is contained in:
Paul Gschwendtner
2018-01-22 21:50:50 +01:00
committed by Jeremy Elbourn
parent 5d77d908d4
commit 7024dc49f8
6 changed files with 22 additions and 85 deletions
-1
View File
@@ -1,2 +1 @@
export {payloadGithubStatus} from './payload-github-status';
export {pullRequestsWithConflicts} from './pull-requests-with-conflicts';
+1 -12
View File
@@ -1,22 +1,11 @@
import {GraphQLClient} from 'graphql-request';
import {config} from 'firebase-functions';
import * as GithubApi from 'github';
import * as GithubApi from '@octokit/rest';
/** API token for the Github repository. Required to set the github status on commits and PRs. */
const githubAccessToken = config().secret.github;
/** API Endpoint for the Github API v4 using GraphQL. */
const githubApiV4Endpoint = 'https://api.github.com/graphql';
/** Export the GitHub V3 API instance that is authenticated. */
export const githubApiV3 = new GithubApi();
/** Export the GraphQL client that can be used to query the Github API v4. */
export const githubApiV4 = new GraphQLClient(githubApiV4Endpoint, {
headers: {
Authorization: `Bearer ${githubAccessToken}`,
}
});
// Authenticate the Github API package with the user token.
githubApiV3.authenticate({type: 'token', token: githubAccessToken});
@@ -1,43 +0,0 @@
import {githubApiV4} from './github-api';
/** GraphQL query that finds all Pull Requests and their mergeable state. */
const getOpenPullRequestsWithMergeableStateQuery = `
query getOpenPullRequestsWithMergeableState($lastCursor: String) {
repository(owner: "angular", name: "material2") {
pullRequests(states: OPEN, first: 100, after: $lastCursor) {
pageInfo {
hasNextPage,
endCursor
}
nodes {
number,
mergeable
}
}
}
}`;
/** Pull Request node that will be returned by the Github V4 API. */
export interface PullRequestWithMergeableState {
number: number;
mergeable: string;
}
/** Queries the GitHub API to find all open pull requests and their mergeable state. */
export async function getOpenPullRequestsWithMergeableState()
: Promise<PullRequestWithMergeableState[]> {
const nodes: PullRequestWithMergeableState[] = [];
let lastData: any|null = null;
while (!lastData || lastData.repository.pullRequests.pageInfo.hasNextPage) {
lastData = await githubApiV4.request(getOpenPullRequestsWithMergeableStateQuery, {
lastCursor: lastData && lastData.repository.pullRequests.pageInfo.endCursor
});
nodes.push(...lastData.repository.pullRequests.nodes);
}
return nodes;
}
+10 -10
View File
@@ -1,16 +1,16 @@
{
"name": "material2-board-functions",
"version": "0.0.1",
"version": "0.0.0",
"main": "index.js",
"dependencies": {
"@types/jsonwebtoken": "^7.2.1",
"firebase-admin": "~4.2.1",
"firebase-functions": "^0.5.7",
"github": "^10.0.0",
"graphql-request": "^1.3.4",
"jsonwebtoken": "^7.4.1",
"request": "^2.81.0",
"ts-node": "^3.0.6",
"typescript": "^2.3.4"
"@firebase/app-types": "^0.1.1",
"@octokit/rest": "^14.0.4",
"@types/jsonwebtoken": "^7.2.5",
"firebase-admin": "^5.8.1",
"firebase-functions": "^0.8.1",
"jsonwebtoken": "^8.1.0",
"request": "^2.83.0",
"ts-node": "^4.1.0",
"typescript": "^2.6.2"
}
}
@@ -38,13 +38,18 @@ export const payloadGithubStatus = https.onRequest(async (request, response) =>
const diffFormatted = Math.abs(packageDiff).toFixed(2);
const packageSizeFormatted = packageSize.toFixed(2);
await setGithubStatus(commitSha, {
result: true,
name: `${capitalizeFirstLetter(packageName)} Payload Size`,
description: `${packageSizeFormatted}kb / ${diffFormatted}kb ${diffMessage} (ES2015 bundle)`
});
try {
await setGithubStatus(commitSha, {
result: true,
name: `${capitalizeFirstLetter(packageName)} Payload Size`,
description: `${packageSizeFormatted}kb / ${diffFormatted}kb ${diffMessage} (ES2015 bundle)`
});
response.json({message: 'Payload Github status successfully set.'});
response.json({message: 'Payload Github status successfully set.'});
} catch (e) {
response.json({message: 'An error occurred while setting the GitHub status.'});
console.error('An error occurred while setting Github status.', e);
}
});
/** Capitalizes the first letter of a string. */
@@ -1,13 +0,0 @@
import {https} from 'firebase-functions';
import {getOpenPullRequestsWithMergeableState} from './github/github-graphql-queries';
/**
* Firebase HTTP trigger that responds with a list of Pull Requests that have merge conflicts.
*/
export const pullRequestsWithConflicts = https.onRequest(async (_request, response) => {
const pullRequests = (await getOpenPullRequestsWithMergeableState())
.filter(pullRequest => pullRequest.mergeable === 'CONFLICTING');
response.status(200).json(pullRequests);
});