Skip to content

Commit 764a5c6

Browse files
committed
extract committer sanitation
1 parent 6a1baff commit 764a5c6

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

src/changelog.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export default class Changelog {
136136
const shouldKeepCommiter = login && !this.ignoreCommitter(login);
137137

138138
if (login && shouldKeepCommiter && !committers[login]) {
139-
committers[login] = await this.github.getUserData(user);
139+
committers[login] = this.sanitizeCommitter(await this.github.getUserData(user));
140140
}
141141
}
142142

@@ -147,6 +147,15 @@ export default class Changelog {
147147
return this.config.ignoreCommitters.some((c: string) => c === login || login.indexOf(c) > -1);
148148
}
149149

150+
private sanitizeCommitter(contributor: GitHubContributor) {
151+
// Response for Copilot is "Copilot SWE Agent" - but we prefer "Copilot"
152+
if (contributor.login === "Copilot") {
153+
contributor.name = "Copilot";
154+
}
155+
156+
return contributor;
157+
}
158+
150159
private toCommitInfos(commits: Git.CommitListItem[]): CommitInfo[] {
151160
return commits.map(commit => {
152161
const { sha, refName, summary: message, date } = commit;

src/github-api.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,14 @@ export default class GithubAPI {
6565
let login = userInfo.login;
6666
let path = "users";
6767

68+
// github API itself does not tell if contributor is an app. Best guess was to
69+
// check the `html_url` for the `/apps/` segment
6870
if (userInfo.html_url && userInfo.html_url.includes("/apps/")) {
6971
path = "apps";
7072
login = userInfo.html_url.split("/").pop() as string;
7173
}
7274
const prefix = process.env.GITHUB_API_URL || `https://api.${this.github}`;
73-
const data = await this._fetch(`${prefix}/${path}/${login}`);
74-
75-
if (login === "Copilot") {
76-
// Response for Copilot is "Copilot SWE Agent" - but we prefer "Copilot"
77-
data.name = "Copilot";
78-
}
79-
80-
return data;
75+
return await this._fetch(`${prefix}/${path}/${login}`);
8176
}
8277

8378
private async _fetch(url: string): Promise<any> {

0 commit comments

Comments
 (0)