Skip to content

Commit 1b75595

Browse files
committed
fix getUseData for apps that aren't bots
1 parent 932b1c7 commit 1b75595

3 files changed

Lines changed: 24 additions & 12 deletions

File tree

src/changelog.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,14 @@ export default class Changelog {
129129

130130
for (const commit of commits) {
131131
const issue = commit.githubIssue;
132-
const login = issue && issue.user && issue.user.login;
132+
const user = issue && issue.user;
133+
const login = user && user.login;
133134
// If a list of `ignoreCommitters` is provided in the lerna.json config
134135
// check if the current committer should be kept or not.
135136
const shouldKeepCommiter = login && !this.ignoreCommitter(login);
137+
136138
if (login && shouldKeepCommiter && !committers[login]) {
137-
committers[login] = await this.github.getUserData(login);
139+
committers[login] = await this.github.getUserData(user);
138140
}
139141
}
140142

src/github-api.spec.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ describe("github api", function () {
1717
};
1818
expect(github.getBaseIssueUrl("foo")).toEqual(`https://github.host.com/foo/issues/`);
1919

20-
github.getUserData("foo");
20+
github.getUserData({ login: "foo", html_url: "" });
2121
expect(fetchedUrl).toEqual(`https://api.github.host.com/users/foo`);
2222

2323
github.getIssueData("foo", "2");
2424
expect(fetchedUrl).toEqual(`https://api.github.host.com/repos/foo/issues/2`);
2525

26+
github.getUserData({ login: "Copilot", html_url: "https://github.com/apps/copilot-swe-agent" });
27+
expect(fetchedUrl).toEqual(`https://api.github.host.com/apps/copilot-swe-agent`);
28+
2629
delete process.env.GITHUB_DOMAIN;
2730

2831
process.env.GITHUB_API_URL = "https://api.github.host2.com";
@@ -36,7 +39,7 @@ describe("github api", function () {
3639
};
3740
expect(github.getBaseIssueUrl("foo")).toEqual(`https://github.com/foo/issues/`);
3841

39-
github.getUserData("foo");
42+
github.getUserData({ login: "foo", html_url: "" });
4043
expect(fetchedUrl).toEqual(`https://api.github.host2.com/users/foo`);
4144

4245
github.getIssueData("foo", "2");

src/github-api.ts

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

6-
export interface GitHubUserResponse {
6+
interface GithubUserInfo {
77
login: string;
8-
name: string;
98
html_url: string;
109
}
1110

11+
export interface GitHubUserResponse extends GithubUserInfo {
12+
name: string;
13+
}
14+
1215
export interface GitHubIssueResponse {
1316
number: number;
1417
title: string;
@@ -18,10 +21,7 @@ export interface GitHubIssueResponse {
1821
labels: Array<{
1922
name: string;
2023
}>;
21-
user: {
22-
login: string;
23-
html_url: string;
24-
};
24+
user: GithubUserInfo;
2525
}
2626

2727
export interface Options {
@@ -54,9 +54,16 @@ export default class GithubAPI {
5454
return this._fetch(`${prefix}/repos/${repo}/issues/${issue}`);
5555
}
5656

57-
public async getUserData(login: string): Promise<GitHubUserResponse> {
57+
public async getUserData(userInfo: GithubUserInfo): Promise<GitHubUserResponse> {
58+
let login = userInfo.login;
59+
let path = "users";
60+
61+
if (userInfo.html_url && userInfo.html_url.includes("/apps/")) {
62+
path = "apps";
63+
login = userInfo.html_url.split("/").pop() as string;
64+
}
5865
const prefix = process.env.GITHUB_API_URL || `https://api.${this.github}`;
59-
return this._fetch(`${prefix}/users/${login}`);
66+
return this._fetch(`${prefix}/${path}/${login}`);
6067
}
6168

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

0 commit comments

Comments
 (0)