From 7abeaad134c61a1695eb61a6d6dbadfdd0e98503 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Tue, 17 Sep 2024 12:34:02 -0700 Subject: [PATCH] feat: set no-notes automatically on build PRs --- package.json | 3 ++- src/constants.ts | 1 + src/index.ts | 18 ++++++++++++++++-- tsconfig.json | 2 +- yarn.lock | 20 ++++++++++++++++---- 5 files changed, 36 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 8b9af03..3061423 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ }, "devDependencies": { "@types/bunyan": "^1.8.6", + "@types/debug": "^4.1.12", "@types/jest": "^29.0.3", "@types/node": "^16.11.7", "debug": "^4.3.4", @@ -18,7 +19,7 @@ "lint-staged": "^13.0.4", "prettier": "^2.7.1", "ts-jest": "^29.0.1", - "typescript": "^4.8.2" + "typescript": "^5.6.2" }, "scripts": { "build": "tsc", diff --git a/src/constants.ts b/src/constants.ts index b1e9495..49cddd2 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,2 +1,3 @@ export const NO_NOTES_BODY = '**No Release Notes**'; export const NOTES_LEAD = '**Release Notes Persisted**'; +export const SEMANTIC_BUILD_PREFIX = 'build:'; diff --git a/src/index.ts b/src/index.ts index 3a73c0f..d055595 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,15 +1,18 @@ +import { PullRequest } from '@octokit/webhooks-types/schema'; import { Probot, Context } from 'probot'; + import * as noteUtils from './note-utils'; import d from 'debug'; +import { SEMANTIC_BUILD_PREFIX } from './constants'; const debug = d('note-utils'); const submitFeedbackForPR = async ( context: Context<'pull_request'>, - pr: any, + pr: PullRequest, shouldComment = false, ) => { - const releaseNotes = noteUtils.findNoteInPRBody(pr.body); + const releaseNotes = pr.body && noteUtils.findNoteInPRBody(pr.body); const github = context.octokit; if (!releaseNotes) { @@ -24,6 +27,17 @@ const submitFeedbackForPR = async ( return; } + if (pr.title.startsWith(SEMANTIC_BUILD_PREFIX)) { + debug("Adding 'Notes: none' to build: PR body"); + await github.pulls.update( + context.repo({ + pull_number: pr.number, + body: pr.body + '\n\n---\n\nNotes: none', + }), + ); + return; + } + debug(`No Release Notes: posting failed check.`); await github.repos.createCommitStatus( context.repo({ diff --git a/tsconfig.json b/tsconfig.json index 527e84b..9ead7e7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,7 +9,7 @@ "sourceMap": true, "rootDir": "src", "experimentalDecorators": true, - "allowJs": true, + "strict": true, "allowSyntheticDefaultImports": true }, "include": [ diff --git a/yarn.lock b/yarn.lock index 62a7329..40020b8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1182,6 +1182,13 @@ dependencies: "@types/node" "*" +"@types/debug@^4.1.12": + version "4.1.12" + resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.12.tgz#a155f21690871953410df4b6b6f53187f0500917" + integrity sha512-vIChWdVG3LG1SMxEvI/AK+FWJthlrqlTu7fbrlywTkkaONwk/UAGaULXRlf8vkzFBLVm0zkMdCquhL5aOjhXPQ== + dependencies: + "@types/ms" "*" + "@types/express-serve-static-core@^4.17.18": version "4.17.31" resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.31.tgz#a1139efeab4e7323834bb0226e62ac019f474b2f" @@ -1269,6 +1276,11 @@ resolved "https://registry.yarnpkg.com/@types/mime/-/mime-3.0.1.tgz#5f8f2bca0a5863cb69bc0b0acd88c96cb1d4ae10" integrity sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA== +"@types/ms@*": + version "0.7.34" + resolved "https://registry.yarnpkg.com/@types/ms/-/ms-0.7.34.tgz#10964ba0dee6ac4cd462e2795b6bebd407303433" + integrity sha512-nG96G3Wp6acyAgJqGasjODb+acrI7KltPiRxzHPXnP3NgI28bpQDRv53olbqGXbfcgF5aiiHmO3xpwEpS5Ld9g== + "@types/node@*", "@types/node@>= 8": version "14.0.4" resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.4.tgz#43a63fc5edce226bed106b31b875165256271107" @@ -4194,10 +4206,10 @@ type-is@~1.6.18: media-typer "0.3.0" mime-types "~2.1.24" -typescript@^4.8.2: - version "4.8.3" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.8.3.tgz#d59344522c4bc464a65a730ac695007fdb66dd88" - integrity sha512-goMHfm00nWPa8UvR/CPSvykqf6dVV8x/dp0c5mFTMTIu0u0FlGWRioyy7Nn0PGAdHxpJZnuO/ut+PpQ8UiHAig== +typescript@^5.6.2: + version "5.6.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.6.2.tgz#d1de67b6bef77c41823f822df8f0b3bcff60a5a0" + integrity sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw== uglify-js@^3.1.4: version "3.9.3"