mirror of
https://github.com/microsoft/vscode.git
synced 2026-09-27 10:37:38 +01:00
add closePullRequest() and adopt in cloud-agent (#1594)
* remove pr extension check * add closePullRequest() and adopt in cloud-agent
This commit is contained in:
@@ -312,6 +312,39 @@ export async function addPullRequestCommentGraphQLRequest(
|
||||
return result?.data?.addComment?.commentEdge?.node || null;
|
||||
}
|
||||
|
||||
export async function closePullRequest(
|
||||
fetcherService: IFetcherService,
|
||||
logService: ILogService,
|
||||
telemetry: ITelemetryService,
|
||||
host: string,
|
||||
token: string | undefined,
|
||||
owner: string,
|
||||
repo: string,
|
||||
pullNumber: number,
|
||||
): Promise<boolean> {
|
||||
logService.debug(`[GitHubAPI] Closing pull request ${owner}/${repo}#${pullNumber}`);
|
||||
|
||||
const result = await makeGitHubAPIRequest(
|
||||
fetcherService,
|
||||
logService,
|
||||
telemetry,
|
||||
host,
|
||||
`repos/${owner}/${repo}/pulls/${pullNumber}`,
|
||||
'POST',
|
||||
token,
|
||||
{ state: 'closed' },
|
||||
'2022-11-28'
|
||||
);
|
||||
|
||||
const success = result?.state === 'closed';
|
||||
if (success) {
|
||||
logService.debug(`[GitHubAPI] Successfully closed pull request ${owner}/${repo}#${pullNumber}`);
|
||||
} else {
|
||||
logService.error(`[GitHubAPI] Failed to close pull request ${owner}/${repo}#${pullNumber}. Its state is ${result?.state}`);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
export async function makeGitHubAPIRequestWithPagination(
|
||||
fetcherService: IFetcherService,
|
||||
logService: ILogService,
|
||||
|
||||
@@ -9,7 +9,7 @@ import { ICAPIClientService } from '../../endpoint/common/capiClient';
|
||||
import { ILogService } from '../../log/common/logService';
|
||||
import { IFetcherService } from '../../networking/common/fetcherService';
|
||||
import { ITelemetryService } from '../../telemetry/common/telemetry';
|
||||
import { addPullRequestCommentGraphQLRequest, getPullRequestFromGlobalId, makeGitHubAPIRequest, makeGitHubAPIRequestWithPagination, makeSearchGraphQLRequest, PullRequestComment, PullRequestSearchItem, SessionInfo } from './githubAPI';
|
||||
import { addPullRequestCommentGraphQLRequest, closePullRequest, getPullRequestFromGlobalId, makeGitHubAPIRequest, makeGitHubAPIRequestWithPagination, makeSearchGraphQLRequest, PullRequestComment, PullRequestSearchItem, SessionInfo } from './githubAPI';
|
||||
|
||||
export type IGetRepositoryInfoResponseData = Endpoints["GET /repos/{owner}/{repo}"]["response"]["data"];
|
||||
|
||||
@@ -252,6 +252,15 @@ export interface IOctoKitService {
|
||||
* @returns An array of changed files with their metadata
|
||||
*/
|
||||
getPullRequestFiles(owner: string, repo: string, pullNumber: number): Promise<PullRequestFile[]>;
|
||||
|
||||
/**
|
||||
* Closes a pull request.
|
||||
* @param owner The repository owner
|
||||
* @param repo The repository name
|
||||
* @param pullNumber The pull request number
|
||||
* @returns A promise that resolves to true if the PR was successfully closed
|
||||
*/
|
||||
closePullRequest(owner: string, repo: string, pullNumber: number): Promise<boolean>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -335,4 +344,8 @@ export class BaseOctoKitService {
|
||||
const result = await makeGitHubAPIRequest(this._fetcherService, this._logService, this._telemetryService, this._capiClientService.dotcomAPIURL, `repos/${owner}/${repo}/pulls/${pullNumber}/files`, 'GET', token, undefined, '2022-11-28');
|
||||
return result || [];
|
||||
}
|
||||
|
||||
protected async closePullRequestWithToken(owner: string, repo: string, pullNumber: number, token: string): Promise<boolean> {
|
||||
return closePullRequest(this._fetcherService, this._logService, this._telemetryService, this._capiClientService.dotcomAPIURL, token, owner, repo, pullNumber);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,4 +170,12 @@ export class OctoKitService extends BaseOctoKitService implements IOctoKitServic
|
||||
}
|
||||
return this.getPullRequestFilesWithToken(owner, repo, pullNumber, authToken);
|
||||
}
|
||||
|
||||
async closePullRequest(owner: string, repo: string, pullNumber: number): Promise<boolean> {
|
||||
const authToken = (await this._authService.getAnyGitHubSession())?.accessToken;
|
||||
if (!authToken) {
|
||||
return false;
|
||||
}
|
||||
return this.closePullRequestWithToken(owner, repo, pullNumber, authToken);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user