Skip to content
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

Unable to create PR in web #3534

Merged
merged 1 commit into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 29 additions & 19 deletions src/github/githubRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
ForkDetailsResponse,
IssuesResponse,
IssuesSearchResponse,
ListBranchesResponse,
MaxIssueResponse,
MentionableUsersResponse,
MilestoneIssuesResponse,
Expand Down Expand Up @@ -732,32 +733,41 @@ export class GitHubRepository implements vscode.Disposable {
}

async listBranches(owner: string, repositoryName: string): Promise<string[]> {
const { octokit } = await this.ensure();
const { query, remote, schema } = await this.ensure();
Logger.debug(`List branches for ${owner}/${repositoryName} - enter`, GitHubRepository.ID);

try {
let branches: string[] = [];
const startingTime = new Date().getTime();
for await (const response of octokit.paginate.iterator<OctokitCommon.ReposListBranchesResponseData>(
'GET /repos/:owner/:repo/branches',
{
owner: owner,
repo: repositoryName,
per_page: 100
},
) as any) {
branches.push(...response.data.map(branch => branch.name));
let after: string | null = null;
let hasNextPage = false;
const branches: string[] = [];
const startingTime = new Date().getTime();

do {
try {
const { data } = await query<ListBranchesResponse>({
query: schema.ListBranches,
variables: {
owner: remote.owner,
name: remote.repositoryName,
first: 100,
after: after,
},
});

branches.push(...data.repository.refs.nodes.map(node => node.name));
if (new Date().getTime() - startingTime > 5000) {
Logger.appendLine('List branches timeout hit.', 'GitHubRepository');
break;
}
hasNextPage = data.repository.refs.pageInfo.hasNextPage;
after = data.repository.refs.pageInfo.endCursor;
} catch (e) {
Logger.debug(`List branches for ${owner}/${repositoryName} failed`, GitHubRepository.ID);
throw e;
}
} while (hasNextPage);

Logger.debug(`List branches for ${owner}/${repositoryName} - done`, GitHubRepository.ID);
return branches;
} catch (e) {
Logger.debug(`List branches for ${owner}/${repositoryName} failed`, GitHubRepository.ID);
throw e;
}
Logger.debug(`List branches for ${owner}/${repositoryName} - done`, GitHubRepository.ID);
return branches;
}

async deleteBranch(pullRequestModel: PullRequestModel): Promise<void> {
Expand Down
14 changes: 14 additions & 0 deletions src/github/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,20 @@ export interface UpdatePullRequestResponse {
};
}

export interface ListBranchesResponse {
repository: {
refs: {
nodes: {
name: string;
}[];
pageInfo: {
hasNextPage: boolean;
endCursor: string;
};
};
};
}

export interface RefRepository {
owner: {
login: string;
Expand Down
14 changes: 14 additions & 0 deletions src/github/queries.gql
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,20 @@ query GetAssignableUsers($owner: String!, $name: String!, $first: Int!, $after:
}
}

query ListBranches($owner: String!, $name: String!, $first: Int!, $after: String) {
repository(owner: $owner, name: $name) {
refs(first: $first, after: $after, refPrefix: "refs/heads/") {
nodes {
name
}
pageInfo {
hasNextPage
endCursor
}
}
}
}

query IssuesWithoutMilestone($owner: String!, $name: String!, $assignee: String!) {
repository(owner: $owner, name: $name) {
issues(
Expand Down