60
});
61
const HeadCommit = Schema.Struct({
62
author: Schema.NullOr(Schema.Struct({ login: Schema.String })),
63
- committer: Schema.NullOr(Schema.Struct({ login: Schema.String })),
63
commit: Schema.Struct({ verification: Schema.Struct({ verified: Schema.Boolean }) }),
64
parents: Schema.Array(Schema.Struct({ sha: Sha })),
65
});
114
return { pull, batch };
115
});
116
117
+const ZERO_SHA = '0'.repeat(40);
118
+const BranchActivity = Schema.Struct({
119
+ after: Sha,
120
+ actor: Schema.NullOr(Schema.Struct({ login: Schema.String })),
121
+});
122
+
123
/**
119
- * Whether the release PR head is the release App's own verified commit on the planned source. A
120
- * person can sign a commit that names the bot as author, but not one it committed.
124
+ * Whether `sha` is the release App's own verified commit on the planned source, and the App set
125
+ * the release branch to it last. GitHub commits and signs every API-made commit as `web-flow`,
126
+ * and any writer can make one that names the App as author, so only the branch's activity log,
127
+ * newest first, shows who moved it.
128
*/
122
-export const isReleaseAppCommit = (sha: string, inputBase: string, appSlug: string) =>
123
- Effect.map(
124
- request('GET', `${REPOSITORY_PATH}/commits/${sha}`, HeadCommit),
125
- head =>
129
+export const isReleaseAppCommit = (sha: string, batch: ReleaseBatch, appSlug: string) =>
130
+ Effect.gen(function* () {
131
+ const head = yield* request('GET', `${REPOSITORY_PATH}/commits/${sha}`, HeadCommit);
132
+ const activity = yield* request(
133
+ 'GET',
134
+ `${REPOSITORY_PATH}/activity?ref=${encodeURIComponent(`refs/heads/${releaseBranch(batch.id)}`)}&direction=desc&per_page=100`,
135
+ Schema.Array(BranchActivity)
136
+ );
137
+ const lastSet = activity.find(entry => entry.after !== ZERO_SHA);
138
+ return (
139
head.author?.login === `${appSlug}[bot]` &&
127
- head.committer?.login === `${appSlug}[bot]` &&
140
head.commit.verification.verified &&
141
head.parents.length === 1 &&
130
- head.parents[0].sha === inputBase
131
- );
142
+ head.parents[0].sha === batch.inputBase &&
143
+ lastSet?.after === sha &&
144
+ lastSet.actor?.login === `${appSlug}[bot]`
145
+ );
146
+ });
147
148
export const isReleaseAppHead = (pull: Pull, batch: ReleaseBatch, appSlug: string) =>
134
- isReleaseAppCommit(pull.head.sha, batch.inputBase, appSlug);
149
+ isReleaseAppCommit(pull.head.sha, batch, appSlug);
150
+
151
+const IssueEvent = Schema.Struct({ event: Schema.String, commit_id: Schema.NullOr(Sha) });
152
+
153
+/** The commit a merged PR left on its base. Pull responses no longer carry `merge_commit_sha`. */
154
+export const mergeCommitOf = (number: number) =>
155
+ Effect.gen(function* () {
156
+ const events = yield* Stream.runCollect(
157
+ paginateArray(`${REPOSITORY_PATH}/issues/${number}/events`, IssueEvent)
158
+ );
159
+ const sha = events.findLast(event => event.event === 'merged')?.commit_id;
160
+ if (!sha) return yield* fail('The merged release PR has no merge commit');
161
+ return sha;
162
+ });
163
164
/**
165
* The request issue named by a release PR's plan, only when the release App committed that plan.