Skip to content

Commit b0c935d

Browse files
committed
Fix tests
1 parent 6288088 commit b0c935d

6 files changed

Lines changed: 56 additions & 23 deletions

File tree

src/changelog.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import progressBar from "./progress-bar";
55
import { Configuration } from "./configuration";
66
import findPullRequestId from "./find-pull-request-id";
77
import * as Git from "./git";
8-
import GithubAPI, { GitHubUserResponse } from "./github-api";
8+
import GithubAPI, { GitHubContributor } from "./github-api";
99
import { CommitInfo, Release } from "./interfaces";
1010
import MarkdownRenderer from "./markdown-renderer";
1111

@@ -124,8 +124,8 @@ export default class Changelog {
124124
return Git.listCommits(from, to);
125125
}
126126

127-
private async getCommitters(commits: CommitInfo[]): Promise<GitHubUserResponse[]> {
128-
const committers: { [id: string]: GitHubUserResponse } = {};
127+
private async getCommitters(commits: CommitInfo[]): Promise<GitHubContributor[]> {
128+
const committers: { [id: string]: GitHubContributor } = {};
129129

130130
for (const commit of commits) {
131131
const issue = commit.githubIssue;

src/github-api.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,22 @@ const path = require("path");
33
import ConfigurationError from "./configuration-error";
44
import fetch from "./fetch";
55

6-
interface GithubUserInfo {
6+
interface GitHubContributorBase {
77
login: string;
8+
name: string;
89
html_url: string;
910
}
1011

11-
export interface GitHubUserResponse extends GithubUserInfo {
12-
name: string;
12+
export interface GithubUserInfo extends GitHubContributorBase {
13+
type: string; // "Bot" | "User"
14+
}
15+
16+
export interface GithubAppInfo extends GitHubContributorBase {
17+
slug: string;
1318
}
1419

20+
export type GitHubContributor = GithubUserInfo | GithubAppInfo;
21+
1522
export interface GitHubIssueResponse {
1623
number: number;
1724
title: string;
@@ -54,7 +61,7 @@ export default class GithubAPI {
5461
return this._fetch(`${prefix}/repos/${repo}/issues/${issue}`);
5562
}
5663

57-
public async getUserData(userInfo: GithubUserInfo): Promise<GitHubUserResponse> {
64+
public async getUserData(userInfo: Pick<GithubUserInfo, "login" | "html_url">): Promise<GitHubContributor> {
5865
let login = userInfo.login;
5966
let path = "users";
6067

@@ -63,7 +70,14 @@ export default class GithubAPI {
6370
login = userInfo.html_url.split("/").pop() as string;
6471
}
6572
const prefix = process.env.GITHUB_API_URL || `https://api.${this.github}`;
66-
return this._fetch(`${prefix}/${path}/${login}`);
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;
6781
}
6882

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

src/interfaces.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { GitHubIssueResponse, GitHubUserResponse } from "./github-api";
1+
import { GitHubIssueResponse, GitHubContributor } from "./github-api";
22

33
export interface CommitInfo {
44
commitSHA: string;
@@ -15,5 +15,5 @@ export interface Release {
1515
name: string;
1616
date: string;
1717
commits: CommitInfo[];
18-
contributors?: GitHubUserResponse[];
18+
contributors?: GitHubContributor[];
1919
}

src/markdown-renderer.spec.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { GithubAppInfo, GithubUserInfo } from "./github-api";
12
import { CommitInfo, Release } from "./interfaces";
23
import MarkdownRenderer from "./markdown-renderer";
34

@@ -120,12 +121,14 @@ describe("MarkdownRenderer", () => {
120121
const user1 = {
121122
login: "hzoo",
122123
name: "",
124+
type: "User",
123125
html_url: "https://github.com/hzoo",
124126
};
125127

126128
const user2 = {
127129
login: "Turbo87",
128130
name: "Tobias Bieniek",
131+
type: "User",
129132
html_url: "https://github.com/Turbo87",
130133
};
131134

@@ -140,6 +143,7 @@ describe("MarkdownRenderer", () => {
140143
const result = renderer().renderContributor({
141144
login: "foo",
142145
name: "",
146+
type: "User",
143147
html_url: "http://github.com/foo",
144148
});
145149

@@ -150,11 +154,23 @@ describe("MarkdownRenderer", () => {
150154
const result = renderer().renderContributor({
151155
login: "foo",
152156
name: "Foo Bar",
157+
type: "User",
153158
html_url: "http://github.com/foo",
154159
});
155160

156161
expect(result).toEqual("Foo Bar ([@foo](http://github.com/foo))");
157162
});
163+
164+
it(`renders Copilot`, () => {
165+
const result = renderer().renderContributor({
166+
login: "Copilot",
167+
name: "Copilot",
168+
slug: "copilot-swe-agent",
169+
html_url: "https://github.com/apps/copilot-swe-agent",
170+
} as GithubAppInfo);
171+
172+
expect(result).toEqual("Copilot [Bot] ([@copilot-swe-agent](https://github.com/apps/copilot-swe-agent))");
173+
});
158174
});
159175

160176
describe("groupByCategory", () => {
@@ -230,7 +246,7 @@ describe("MarkdownRenderer", () => {
230246
categories: [":rocket: New Feature"],
231247
},
232248
],
233-
contributors: [{ name: "Henry", login: "hzoo", html_url: "http://hzoo.com" }],
249+
contributors: [{ name: "Henry", login: "hzoo", type: "User", html_url: "http://hzoo.com" }],
234250
};
235251
const options = {
236252
categories: [":rocket: New Feature"],

src/markdown-renderer.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { GitHubUserResponse } from "./github-api";
1+
import { GitHubContributor, type GithubAppInfo, type GithubUserInfo } from "./github-api";
22
import { CommitInfo, Release } from "./interfaces";
33

44
const UNRELEASED_TAG = "___unreleased___";
@@ -114,16 +114,19 @@ export default class MarkdownRenderer {
114114
}
115115
}
116116

117-
public renderContributorList(contributors: GitHubUserResponse[]) {
117+
public renderContributorList(contributors: GitHubContributor[]) {
118118
const renderedContributors = contributors.map(contributor => `- ${this.renderContributor(contributor)}`).sort();
119119

120120
return `#### Committers: ${contributors.length}\n${renderedContributors.join("\n")}`;
121121
}
122122

123-
public renderContributor(contributor: GitHubUserResponse): string {
124-
const userNameAndLink = `[@${contributor.login}](${contributor.html_url})`;
123+
public renderContributor(contributor: GitHubContributor): string {
124+
const userName = (contributor as GithubAppInfo).slug ?? (contributor as GithubUserInfo).login;
125+
const userNameAndLink = `[@${userName}](${contributor.html_url})`;
126+
125127
if (contributor.name) {
126-
return `${contributor.name} (${userNameAndLink})`;
128+
const name = contributor.name + (!("type" in contributor) ? " [Bot]" : "");
129+
return `${name} (${userNameAndLink})`;
127130
} else {
128131
return userNameAndLink;
129132
}

tests/basic-acceptance.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe.skipIf(!process.env.GITHUB_AUTH)("command line interface", () => {
1919
2020
#### :rocket: Enhancement
2121
* \`github-changelog\`
22-
* [#33](https://github.com/embroider-build/github-changelog/pull/33) support github enterpise url detection and env vars ([@patricklx](https://github.com/patricklx))
22+
* [#33](https://github.com/release-plan/github-changelog/pull/33) support github enterpise url detection and env vars ([@patricklx](https://github.com/patricklx))
2323
2424
#### Committers: 1
2525
- Patrick Pircher ([@patricklx](https://github.com/patricklx))
@@ -29,10 +29,10 @@ describe.skipIf(!process.env.GITHUB_AUTH)("command line interface", () => {
2929
3030
#### :house: Internal
3131
* \`github-changelog\`
32-
* [#29](https://github.com/embroider-build/github-changelog/pull/29) Prepare Release ([@github-actions[bot]](https://github.com/apps/github-actions))
32+
* [#29](https://github.com/release-plan/github-changelog/pull/29) Prepare Release ([@github-actions[bot]](https://github.com/apps/github-actions))
3333
3434
#### Committers: 1
35-
- [@github-actions[bot]](https://github.com/apps/github-actions)"
35+
- GitHub Actions [Bot] ([@github-actions](https://github.com/apps/github-actions))"
3636
`);
3737
});
3838

@@ -46,15 +46,15 @@ describe.skipIf(!process.env.GITHUB_AUTH)("command line interface", () => {
4646
4747
#### :rocket: Enhancement
4848
* \`github-changelog\`
49-
* [#33](https://github.com/embroider-build/github-changelog/pull/33) support github enterpise url detection and env vars ([@patricklx](https://github.com/patricklx))
49+
* [#33](https://github.com/release-plan/github-changelog/pull/33) support github enterpise url detection and env vars ([@patricklx](https://github.com/patricklx))
5050
5151
#### :house: Internal
5252
* \`github-changelog\`
53-
* [#29](https://github.com/embroider-build/github-changelog/pull/29) Prepare Release ([@github-actions[bot]](https://github.com/apps/github-actions))
53+
* [#29](https://github.com/release-plan/github-changelog/pull/29) Prepare Release ([@github-actions[bot]](https://github.com/apps/github-actions))
5454
5555
#### Committers: 2
56-
- Patrick Pircher ([@patricklx](https://github.com/patricklx))
57-
- [@github-actions[bot]](https://github.com/apps/github-actions)"
56+
- GitHub Actions [Bot] ([@github-actions](https://github.com/apps/github-actions))
57+
- Patrick Pircher ([@patricklx](https://github.com/patricklx))"
5858
`);
5959
});
6060
});

0 commit comments

Comments
 (0)