diff --git a/package.json b/package.json index d28d39e..c376f1e 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "", "scripts": { "build": "tsc", + "postinstall": "node scripts/printSHA.js", "watch": "tsc -w", "prestart": "npm run build", "start": "func start", diff --git a/scripts/printSHA.js b/scripts/printSHA.js new file mode 100644 index 0000000..04220dc --- /dev/null +++ b/scripts/printSHA.js @@ -0,0 +1,6 @@ +const sha = require('child_process').execSync('git rev-parse HEAD').toString().trim() + +const newFileContents = `// This file is auto-generated in printSHA.js +export const sha = "${sha}"` +require('fs').writeFileSync("src/sha.ts", newFileContents) +console.log("Updated src/sha.ts with current sha") diff --git a/src/checks/addLabelForTeamMember.ts b/src/checks/addLabelForTeamMember.ts index 94522e3..7f4cd43 100644 --- a/src/checks/addLabelForTeamMember.ts +++ b/src/checks/addLabelForTeamMember.ts @@ -12,10 +12,10 @@ export const addLabelForTeamMember = async (api: Octokit, payload: WebhookPayloa // Check the access level of the user const isTeamMember = await isMemberOfTypeScriptTeam(pull_request.user.login, api); if (!isTeamMember) { - return logger(`Skipping because ${pull_request.user.login} is not a member of the TS team`) + return logger.info(`Skipping because ${pull_request.user.login} is not a member of the TS team`) } // Add the label await api.issues.addLabels({ labels: ["Author: Team"], repo: repo.name, owner: repo.owner.login, issue_number: pull_request.id }); - logger("Added labels to PR") + logger.info("Added labels to PR") }; diff --git a/src/checks/assignSelfToNewPullRequest.ts b/src/checks/assignSelfToNewPullRequest.ts index b8892c8..059c23b 100644 --- a/src/checks/assignSelfToNewPullRequest.ts +++ b/src/checks/assignSelfToNewPullRequest.ts @@ -10,7 +10,7 @@ import { Logger } from "@azure/functions"; export const assignSelfToNewPullRequest = async (api: Octokit, payload: WebhookPayloadPullRequest, logger: Logger) => { const { repository: repo, pull_request } = payload; if (pull_request.assignees.length > 0) { - return logger("Skipping because there are assignees already") + return logger.info("Skipping because there are assignees already") } const author = pull_request.user; @@ -25,10 +25,10 @@ export const assignSelfToNewPullRequest = async (api: Octokit, payload: WebhookP // Check the access level of the user const isTeamMember = await isMemberOfTypeScriptTeam(author.login, api); if (isTeamMember) { - logger(`Adding ${author.login} as the assignee`) + logger.info(`Adding ${author.login} as the assignee`) await api.issues.addAssignees({ ...thisIssue, assignees: [author.login] }); } else { - logger(`Skipping because they are not a TS team member`) + logger.info(`Skipping because they are not a TS team member`) } }; diff --git a/src/typeScriptHandlePullRequest.ts b/src/typeScriptHandlePullRequest.ts index 253a856..10cffcf 100644 --- a/src/typeScriptHandlePullRequest.ts +++ b/src/typeScriptHandlePullRequest.ts @@ -4,13 +4,15 @@ import { createGitHubClient } from "./util/createGitHubClient"; import { assignSelfToNewPullRequest } from "./checks/assignSelfToNewPullRequest"; import { addLabelForTeamMember } from "./checks/addLabelForTeamMember"; import Octokit = require("@octokit/rest"); - +import {sha} from "./sha" export const handlePullRequestPayload = async (payload: WebhookPayloadPullRequest, context: Context) => { const api = createGitHubClient(); + const ran = [] as string[] const run = (name: string, fn: (api: Octokit, payload: WebhookPayloadPullRequest, logger: Logger) => Promise) => { - context.log(`\n\n## ${name}\n`) + context.log.info(`\n\n## ${name}\n`) + ran.push(name) return fn(api, payload, context.log) } @@ -20,6 +22,7 @@ export const handlePullRequestPayload = async (payload: WebhookPayloadPullReques context.res = { status: 200, - body: "Success" + headers: { sha: sha }, + body: `Success, ran: ${ran.join(", ")}` }; };