-
Notifications
You must be signed in to change notification settings - Fork 4
fix getUserData for apps that aren't bots
#57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,12 +3,22 @@ const path = require("path"); | |
| import ConfigurationError from "./configuration-error"; | ||
| import fetch from "./fetch"; | ||
|
|
||
| export interface GitHubUserResponse { | ||
| login: string; | ||
| interface GitHubContributorBase { | ||
| name: string; | ||
| html_url: string; | ||
| } | ||
|
|
||
| export interface GithubUserInfo extends GitHubContributorBase { | ||
| login: string; | ||
| type: string; // "Bot" | "User" | ||
| } | ||
|
|
||
| export interface GithubAppInfo extends GitHubContributorBase { | ||
| slug: string; | ||
| } | ||
|
|
||
| export type GitHubContributor = GithubUserInfo | GithubAppInfo; | ||
|
|
||
| export interface GitHubIssueResponse { | ||
| number: number; | ||
| title: string; | ||
|
|
@@ -18,10 +28,7 @@ export interface GitHubIssueResponse { | |
| labels: Array<{ | ||
| name: string; | ||
| }>; | ||
| user: { | ||
| login: string; | ||
| html_url: string; | ||
| }; | ||
| user: GithubUserInfo; | ||
| } | ||
|
|
||
| export interface Options { | ||
|
|
@@ -54,9 +61,18 @@ export default class GithubAPI { | |
| return this._fetch(`${prefix}/repos/${repo}/issues/${issue}`); | ||
| } | ||
|
|
||
| public async getUserData(login: string): Promise<GitHubUserResponse> { | ||
| public async getUserData(userInfo: Pick<GithubUserInfo, "login" | "html_url">): Promise<GitHubContributor> { | ||
| let login = userInfo.login; | ||
| let path = "users"; | ||
|
|
||
| // github API itself does not tell if contributor is an app. Best guess was to | ||
| // check the `html_url` for the `/apps/` segment | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see, apps are a sub-type of Bot.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I'm not really sure that Github knows what it is doing. That seems very much like an impl without spec: "we need it, make it happen, doesn't matter how". |
||
| if (userInfo.html_url && userInfo.html_url.includes("/apps/")) { | ||
| path = "apps"; | ||
| login = userInfo.html_url.split("/").pop() as string; | ||
| } | ||
| const prefix = process.env.GITHUB_API_URL || `https://api.${this.github}`; | ||
| return this._fetch(`${prefix}/users/${login}`); | ||
| return await this._fetch(`${prefix}/${path}/${login}`); | ||
| } | ||
|
|
||
| private async _fetch(url: string): Promise<any> { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.