(github, variables, snapshot)
| 43 | } |
| 44 | |
| 45 | async function readComparison(github, variables, snapshot) { |
| 46 | const commits = new Map(); |
| 47 | for (let page = 1; commits.size < snapshot.count; page += 1) { |
| 48 | const { data } = await github.rest.repos.compareCommitsWithBasehead({ |
| 49 | owner: variables.owner, |
| 50 | repo: variables.repo, |
| 51 | basehead: `${snapshot.base}...${snapshot.head}`, |
| 52 | per_page: 100, |
| 53 | page, |
| 54 | }); |
| 55 | if (!data || data.total_commits !== snapshot.count || |
| 56 | !Array.isArray(data.commits) || data.commits.length === 0) { |
| 57 | throw new Error("Unable to read the complete PR commit comparison. Re-run PR Commit Policy."); |
| 58 | } |
| 59 | collectCommits(commits, data.commits.map((entry) => ({ |
| 60 | commit: entry && { oid: entry.sha, message: entry.commit?.message }, |
| 61 | }))); |
| 62 | } |
| 63 | if (commits.size !== snapshot.count || !commits.has(snapshot.head)) { |
| 64 | throw new Error("PR commit comparison does not match its head and count. Re-run PR Commit Policy."); |
| 65 | } |
| 66 | const response = await github.graphql(QUERY, { ...variables, cursor: null }); |
| 67 | const current = response.repository?.pullRequest; |
| 68 | if (!current || current.title !== snapshot.title || current.baseRefOid !== snapshot.base || |
| 69 | current.headRefOid !== snapshot.head || current.commits?.totalCount !== snapshot.count) { |
| 70 | throw new Error("PR changed during validation. Check the run for the latest PR update."); |
| 71 | } |
| 72 | return { title: snapshot.title, head: snapshot.head, commits: [...commits.values()] }; |
| 73 | } |
| 74 | |
| 75 | async function readPullRequest(github, variables) { |
| 76 | let snapshot; |
no test coverage detected