11import * as core from "@actions/core"
22import * as github from "@actions/github"
3+ import type { RestEndpointMethodTypes } from "@octokit/plugin-rest-endpoint-methods"
4+
5+ import { checkReleaseCommits , type ReleaseCheckCommit , type ReleaseCommit } from "./release-check.js"
36
47type Octokit = ReturnType < typeof github . getOctokit >
5- type CompareResponse = Awaited < ReturnType < Octokit [ "rest" ] [ "repos" ] [ "compareCommitsWithBasehead" ] > > [ "data" ]
6- type ListedCommit = Awaited < ReturnType < Octokit [ "rest" ] [ "repos" ] [ "listCommits" ] > > [ "data" ] [ number ]
7- type ReleaseCommit = CompareResponse [ "commits" ] [ number ] | ListedCommit
8- type LatestRelease = Awaited < ReturnType < Octokit [ "rest" ] [ "repos" ] [ "getLatestRelease" ] > > [ "data" ]
8+ type LatestRelease = RestEndpointMethodTypes [ "repos" ] [ "getLatestRelease" ] [ "response" ] [ "data" ]
99
1010const initialVersion = "0.1.0"
1111const patchVersionPattern = / ^ ( v ? ) ( \d + ) \. ( \d + ) \. ( \d + ) $ /
1212
13- const botAuthorLogins = new Set ( [ "renovate[bot]" , "dependabot[bot]" ] )
14- const botAuthorNames = new Set ( [ "renovate bot" , "renovate[bot]" , "dependabot[bot]" , "dependabot" ] )
15- const dependencyPullRequestLabels = new Set ( [ "dependencies" ] )
16- const maintenancePullRequestLabels = new Set ( [ "test" , "chore" , "refactoring" , "ci" ] )
17- const botEmailFragments = [
18- "renovate[bot]@users.noreply.github.com" ,
19- "bot@renovateapp.com" ,
20- "dependabot[bot]@users.noreply.github.com" ,
21- "dependabot@github.com"
22- ]
23-
2413run ( ) . catch ( ( error : unknown ) => {
2514 core . setFailed ( error instanceof Error ? error . message : String ( error ) )
2615} )
@@ -44,7 +33,7 @@ async function run() {
4433 }
4534
4635 const { commitCount, commits, nextTag, revisionDescription } = releasePreparation
47- const { blockingCommits, hasDependencyUpdateCommit } = await checkReleaseCommits ( octokit , owner , repo , commits )
36+ const { blockingCommits, hasDependencyUpdateCommit } = await getReleaseCheck ( octokit , owner , repo , commits )
4837 if ( blockingCommits . length > 0 ) {
4938 const commitList = blockingCommits
5039 . slice ( 0 , 10 )
@@ -223,49 +212,25 @@ async function listCommits(octokit: Octokit, owner: string, repo: string, branch
223212 } )
224213}
225214
226- async function checkReleaseCommits ( octokit : Octokit , owner : string , repo : string , commits : ReleaseCommit [ ] ) {
227- const blockingCommits = [ ]
228- let hasDependencyUpdateCommit = false
229-
230- for ( const commit of commits ) {
231- const pullRequestLabels = await getAssociatedPullRequestLabels ( octokit , owner , repo , commit )
232-
233- if ( isDependencyUpdateCommit ( commit , pullRequestLabels ) ) {
234- hasDependencyUpdateCommit = true
235- continue
236- }
237-
238- if ( isMaintenanceCommit ( pullRequestLabels ) ) {
239- continue
240- }
241-
242- blockingCommits . push ( commit )
243- }
215+ async function getReleaseCheck ( octokit : Octokit , owner : string , repo : string , commits : ReleaseCommit [ ] ) {
216+ const releaseCheckCommits = await getReleaseCheckCommits ( octokit , owner , repo , commits )
217+ const { blockingCommits, hasDependencyUpdateCommit } = checkReleaseCommits ( releaseCheckCommits )
244218
245219 return { blockingCommits, hasDependencyUpdateCommit }
246220}
247221
248- function isDependencyUpdateCommit ( commit : ReleaseCommit , pullRequestLabels : string [ ] ) {
249- return isDependencyBotCommit ( commit ) || hasPullRequestLabel ( pullRequestLabels , dependencyPullRequestLabels )
250- }
251-
252- function isMaintenanceCommit ( pullRequestLabels : string [ ] ) {
253- return hasPullRequestLabel ( pullRequestLabels , maintenancePullRequestLabels )
254- }
255-
256- function isDependencyBotCommit ( commit : ReleaseCommit ) {
257- const login = commit . author ?. login . toLowerCase ( )
258- if ( login && botAuthorLogins . has ( login ) ) {
259- return true
260- }
222+ async function getReleaseCheckCommits ( octokit : Octokit , owner : string , repo : string , commits : ReleaseCommit [ ] ) {
223+ const releaseCheckCommits : Array < ReleaseCommit & ReleaseCheckCommit > = [ ]
261224
262- const authorName = commit . commit . author ?. name ?. toLowerCase ( )
263- if ( authorName && botAuthorNames . has ( authorName ) ) {
264- return true
225+ for ( const commit of commits ) {
226+ const pullRequestLabels = await getAssociatedPullRequestLabels ( octokit , owner , repo , commit )
227+ releaseCheckCommits . push ( {
228+ ...commit ,
229+ pullRequestLabels
230+ } )
265231 }
266232
267- const authorEmail = commit . commit . author ?. email ?. toLowerCase ( )
268- return Boolean ( authorEmail && botEmailFragments . some ( ( fragment ) => authorEmail . includes ( fragment ) ) )
233+ return releaseCheckCommits
269234}
270235
271236async function getAssociatedPullRequestLabels ( octokit : Octokit , owner : string , repo : string , commit : ReleaseCommit ) {
@@ -278,10 +243,6 @@ async function getAssociatedPullRequestLabels(octokit: Octokit, owner: string, r
278243 return pullRequests . flatMap ( ( pullRequest ) => pullRequest . labels . map ( ( label ) => label . name . toLowerCase ( ) ) )
279244}
280245
281- function hasPullRequestLabel ( labelNames : string [ ] , matchingLabels : Set < string > ) {
282- return labelNames . some ( ( labelName ) => matchingLabels . has ( labelName ) )
283- }
284-
285246async function tagExists ( octokit : Octokit , owner : string , repo : string , tag : string ) {
286247 try {
287248 await octokit . rest . git . getRef ( { owner, repo, ref : `tags/${ tag } ` } )
0 commit comments