-
-
Notifications
You must be signed in to change notification settings - Fork 626
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(bot): apply pre-created patch instead of running npm scripts for …
…lint (#1736)
- Loading branch information
Showing
4 changed files
with
98 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/// <reference path="types.d.ts" /> | ||
// @ts-check | ||
|
||
/** | ||
* @param {{github: Github, context: Context}} param | ||
*/ | ||
async function main(param) { | ||
const { github, context } = param; | ||
|
||
const options = { | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
}; | ||
|
||
// Get PR info | ||
const { data: pull } = await github.pulls.get({ | ||
...options, | ||
pull_number: context.issue.number, | ||
}); | ||
const { data: checks } = await github.checks.listForRef({ | ||
...options, | ||
ref: pull.head.sha, | ||
}); | ||
// Find the correct check | ||
const lintCheck = checks.check_runs.find( | ||
(r) => r.conclusion === "failure" && r.name.startsWith("lint"), | ||
); | ||
if (!lintCheck) return undefined; | ||
|
||
const { data: job } = await github.actions.getJobForWorkflowRun({ | ||
...options, | ||
job_id: lintCheck.id, | ||
}); | ||
const { | ||
data: { artifacts }, | ||
} = await github.actions.listWorkflowRunArtifacts({ | ||
...options, | ||
// @ts-expect-error for some reason job is `never` | ||
run_id: job.run_id, | ||
}); | ||
|
||
if (!artifacts.length) return undefined; | ||
|
||
const { url } = await github.actions.downloadArtifact({ | ||
...options, | ||
artifact_id: artifacts[0].id, | ||
archive_format: "zip", | ||
}); | ||
|
||
return { | ||
repoName: pull.head.repo.full_name, | ||
headRef: pull.head.ref, | ||
patchUrl: url, | ||
}; | ||
} | ||
module.exports = main; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters