Skip to content

Commit ca89a5a

Browse files
committed
Improve GithubRepositoryProvider.getUserRepos
The graphql query is extend to mimic what you would see in Top Repositories box visiting github.com.
1 parent 9b06d2e commit ca89a5a

File tree

1 file changed

+45
-16
lines changed

1 file changed

+45
-16
lines changed

components/server/src/github/github-repository-provider.ts

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -172,28 +172,57 @@ export class GithubRepositoryProvider implements RepositoryProvider {
172172
}
173173

174174
async getUserRepos(user: User): Promise<string[]> {
175-
// Hint: Use this to get richer results:
176-
// node {
177-
// nameWithOwner
178-
// shortDescriptionHTML(limit: 120)
179-
// url
180-
// }
181175
const result: any = await this.githubQueryApi.runQuery(
182176
user,
183177
`
184-
query {
178+
fragment Repos on RepositoryConnection {
179+
nodes {
180+
url
181+
}
182+
}
183+
184+
query topRepositories {
185185
viewer {
186-
repositoriesContributedTo(includeUserRepositories: true, first: 100) {
187-
edges {
188-
node {
189-
url
190-
}
191-
}
192-
}
186+
contributedTo: repositoriesContributedTo(
187+
first: 100
188+
orderBy: {field: PUSHED_AT, direction: DESC}
189+
includeUserRepositories: true
190+
contributionTypes: [COMMIT]
191+
) {
192+
...Repos
193+
}
194+
original: repositories(
195+
first: 100
196+
ownerAffiliations: OWNER
197+
privacy: PUBLIC
198+
isFork: false
199+
isLocked: false
200+
orderBy: {field: UPDATED_AT, direction: DESC}
201+
) {
202+
...Repos
203+
}
204+
forked: repositories(
205+
first: 100
206+
ownerAffiliations: OWNER
207+
privacy: PUBLIC
208+
isFork: true
209+
isLocked: false
210+
orderBy: {field: UPDATED_AT, direction: DESC}
211+
) {
212+
...Repos
213+
}
193214
}
194-
}`,
215+
}`,
195216
);
196-
return (result.data.viewer?.repositoriesContributedTo?.edges || []).map((edge: any) => edge.node.url);
217+
218+
const urls = [];
219+
for (const type of ["contributedTo", "original", "forked"]) {
220+
const nodes = result.data.viewer[type]?.nodes;
221+
if (nodes) {
222+
urls.push(nodes.map((n: any) => n?.url).filter((u: any) => typeof u === "string"));
223+
}
224+
}
225+
return urls;
197226
}
198227

199228
async hasReadAccess(user: User, owner: string, repo: string): Promise<boolean> {

0 commit comments

Comments
 (0)