11/**
22 * Used in `/.github/workflows/pkg.pr.new.yml`
33 */
4+ /**
5+ * @param {object } params
6+ * @param {import('@actions/github/lib/utils').GitHub } params.github
7+ * @param {import('@actions/github/lib/context').Context } params.context
8+ * @param {object } params.output
9+ * @param {string } params.output.sha
10+ * @param {string } params.output.number
11+ * @param {Array<{name: string, url: string}> } params.output.packages
12+ */
413export default async function ( { github, context, output } ) {
514 // eslint-disable-next-line no-console -- For debugging on github actions.
615 console . log ( "pkg-pr-new publish output:" , JSON . stringify ( output ) )
716
8- const sha =
9- context . eventName === "pull_request"
10- ? context . payload . pull_request . head . sha
11- : context . payload . after
17+ const sha = output . sha
1218 const commitUrl = `https://github.com/${ context . repo . owner } /${ context . repo . repo } /commit/${ sha } `
1319
1420 const pullRequestNumber = await getPullRequestNumber ( )
@@ -21,17 +27,15 @@ export default async function ({ github, context, output }) {
2127 const repoPath = `/${ context . repo . owner } /${ context . repo . repo } /`
2228 normalizedUrl = normalizedUrl . replace ( repoPath , "/" )
2329
24- return {
25- name : p . name ,
26- url : normalizedUrl ,
27- }
30+ return { name : p . name , url : normalizedUrl }
2831 } )
2932
3033 const botCommentIdentifier = "<!-- posted by pkg.pr.new-comment.mjs -->"
3134
3235 const onlineUrl = new URL (
3336 "https://eslint-online-playground.netlify.app/#eslint-plugin-astro" ,
3437 )
38+ /** @type {Record<string,string> } */
3539 const overrideDeps = { }
3640 for ( const p of packages ) {
3741 overrideDeps [ p . name ] = p . url
@@ -71,48 +75,37 @@ ${packages.map((p) => `- ${p.name}: ${p.url}`).join("\n")}
7175 /**
7276 * Get the pull request number from the context.
7377 */
74- async function getPullRequestNumber ( ) {
75- if ( context . eventName === "pull_request" ) {
76- if ( context . issue . number ) {
77- return context . issue . number
78- }
79- } else if ( context . eventName === "push" ) {
80- const pullRequests = await github . rest . pulls . list ( {
81- owner : context . repo . owner ,
82- repo : context . repo . repo ,
83- state : "open" ,
84- head : `${ context . repo . owner } :${ context . ref . replace ( "refs/heads/" , "" ) } ` ,
85- } )
86-
87- if ( pullRequests . data . length > 0 ) {
88- return pullRequests . data [ 0 ] . number
89- }
90- }
91- return null
78+ function getPullRequestNumber ( ) {
79+ return output . number
9280 }
9381
9482 /**
9583 * Find the bot comment in the pull request.
84+ * @param {string } issueNumber The pull request number.
9685 */
9786 async function findBotComment ( issueNumber ) {
9887 if ( ! issueNumber ) return null
88+ // @ts -expect-error -- The ID defined in the GitHub API.
9989 const comments = await github . rest . issues . listComments ( {
10090 owner : context . repo . owner ,
10191 repo : context . repo . repo ,
10292 // eslint-disable-next-line camelcase -- The ID defined in the GitHub API.
10393 issue_number : issueNumber ,
10494 } )
95+ // @ts -expect-error
10596 return comments . data . find ( ( comment ) =>
10697 comment . body . includes ( botCommentIdentifier ) ,
10798 )
10899 }
109100
110101 /**
111102 * Create or update the bot comment in the pull request.
103+ * @param {string } issueNumber The pull request number.
112104 */
113105 async function createOrUpdateComment ( issueNumber ) {
114106 const existingComment = await findBotComment ( issueNumber )
115107 if ( existingComment ) {
108+ // @ts -expect-error -- The ID defined in the GitHub API.
116109 await github . rest . issues . updateComment ( {
117110 owner : context . repo . owner ,
118111 repo : context . repo . repo ,
@@ -121,6 +114,7 @@ ${packages.map((p) => `- ${p.name}: ${p.url}`).join("\n")}
121114 body,
122115 } )
123116 } else {
117+ // @ts -expect-error -- The ID defined in the GitHub API.
124118 await github . rest . issues . createComment ( {
125119 // eslint-disable-next-line camelcase -- The ID defined in the GitHub API.
126120 issue_number : issueNumber ,
0 commit comments