Improve logging hopefully
This commit is contained in:
Родитель
773ea5a37c
Коммит
3646e6b2dc
|
@ -4,6 +4,7 @@
|
|||
"description": "",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"postinstall": "node scripts/printSHA.js",
|
||||
"watch": "tsc -w",
|
||||
"prestart": "npm run build",
|
||||
"start": "func start",
|
||||
|
|
|
@ -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")
|
|
@ -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")
|
||||
};
|
||||
|
|
|
@ -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`)
|
||||
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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<void>) => {
|
||||
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(", ")}`
|
||||
};
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче