A merge says which files it changed #128
@@ -229,6 +229,17 @@ export class GiteaClient {
|
|||||||
return GiteaClient.mapPull(await this.request<any>(`/repos/${owner}/${repo}/pulls/${index}`));
|
return GiteaClient.mapPull(await this.request<any>(`/repos/${owner}/${repo}/pulls/${index}`));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The files a merged pull request changed, as paths from the repository's root.
|
||||||
|
*
|
||||||
|
* `limit` is what is asked for, and a merge that changed more says so rather than being read
|
||||||
|
* page by page: what the mesh does with a partial list is treat the whole repository as changed,
|
||||||
|
* so more pages would buy nothing. */
|
||||||
|
async listPullFiles(owner: string, repo: string, index: number, limit = 100): Promise<{ paths: string[]; truncated: boolean }> {
|
||||||
|
const files = await this.request<any[]>(`/repos/${owner}/${repo}/pulls/${index}/files?limit=${limit}`);
|
||||||
|
const paths = (files ?? []).map((f) => String(f?.filename ?? "")).filter((p) => p !== "");
|
||||||
|
return { paths, truncated: paths.length >= limit };
|
||||||
|
}
|
||||||
|
|
||||||
async createPullRequest(
|
async createPullRequest(
|
||||||
owner: string,
|
owner: string,
|
||||||
repo: string,
|
repo: string,
|
||||||
|
|||||||
@@ -95,6 +95,10 @@ async function pollMerged(client: GiteaClient): Promise<void> {
|
|||||||
// at once.
|
// at once.
|
||||||
const fresh = !!pull.merged_at && !!since && pull.merged_at > since;
|
const fresh = !!pull.merged_at && !!since && pull.merged_at > since;
|
||||||
if (primedMerges && fresh) {
|
if (primedMerges && fresh) {
|
||||||
|
// What it changed, asked for only now: a module is rebuilt because a file inside its own
|
||||||
|
// directory moved, and without this every module built from a repository is rebuilt for a
|
||||||
|
// change to any of them (novox/hq 04-ISSUES/131).
|
||||||
|
const changed = await client.listPullFiles(repo.owner, repo.name, pull.number);
|
||||||
await emit("pull.merged", {
|
await emit("pull.merged", {
|
||||||
owner: repo.owner,
|
owner: repo.owner,
|
||||||
repo: repo.name,
|
repo: repo.name,
|
||||||
@@ -106,6 +110,8 @@ async function pollMerged(client: GiteaClient): Promise<void> {
|
|||||||
merged_at: pull.merged_at,
|
merged_at: pull.merged_at,
|
||||||
clone_url: repo.clone_url,
|
clone_url: repo.clone_url,
|
||||||
html_url: pull.html_url,
|
html_url: pull.html_url,
|
||||||
|
paths: changed.paths,
|
||||||
|
paths_truncated: changed.truncated,
|
||||||
});
|
});
|
||||||
// Said, because a trigger that fires silently is indistinguishable from one that did not
|
// Said, because a trigger that fires silently is indistinguishable from one that did not
|
||||||
// fire (novox/hq 04-ISSUES/131) — this line is how an operator knows the mesh was told.
|
// fire (novox/hq 04-ISSUES/131) — this line is how an operator knows the mesh was told.
|
||||||
|
|||||||
@@ -233,6 +233,9 @@ export function getGiteaTools(gitea: GiteaClient): ToolDefinition[] {
|
|||||||
await gitea.mergePullRequest(owner, repo, number, method, deleteBranch);
|
await gitea.mergePullRequest(owner, repo, number, method, deleteBranch);
|
||||||
// Read it again: the merge commit only exists now, and it is what a build is made from.
|
// Read it again: the merge commit only exists now, and it is what a build is made from.
|
||||||
const merged = await gitea.getPullRequest(owner, repo, number);
|
const merged = await gitea.getPullRequest(owner, repo, number);
|
||||||
|
// And what it changed, so the mesh rebuilds the modules whose own files moved rather than
|
||||||
|
// every module built from the repository (novox/hq 04-ISSUES/131).
|
||||||
|
const changed = await gitea.listPullFiles(owner, repo, number);
|
||||||
await emit("pull.merged", {
|
await emit("pull.merged", {
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
@@ -244,6 +247,8 @@ export function getGiteaTools(gitea: GiteaClient): ToolDefinition[] {
|
|||||||
merged_at: merged.merged_at,
|
merged_at: merged.merged_at,
|
||||||
method,
|
method,
|
||||||
html_url: pull.html_url,
|
html_url: pull.html_url,
|
||||||
|
paths: changed.paths,
|
||||||
|
paths_truncated: changed.truncated,
|
||||||
});
|
});
|
||||||
return { merged: true, number, method, deleted_branch: deleteBranch };
|
return { merged: true, number, method, deleted_branch: deleteBranch };
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user