Merge pull request #913 from akv-platform/v-sdolin/push-ref

Skip deleting the branch in the upstream of a forked repo
This commit is contained in:
Sergey Dolin 2023-01-26 08:58:51 +01:00 committed by GitHub
commit c4a13d8dca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 1352 additions and 1326 deletions

View File

@ -130,7 +130,8 @@ class IssuesProcessorBuilder {
number: 0,
draft: true,
head: {
ref: 'ref'
ref: 'ref',
repo: null
}
});
}

31
dist/index.js vendored
View File

@ -921,20 +921,27 @@ class IssuesProcessor {
return;
}
const branch = pullRequest.head.ref;
issueLogger.info(`Deleting the branch "${logger_service_1.LoggerService.cyan(branch)}" from closed $$type`);
try {
this._consumeIssueOperation(issue);
(_a = this.statistics) === null || _a === void 0 ? void 0 : _a.incrementDeletedBranchesCount();
if (!this.options.debugOnly) {
yield this.client.rest.git.deleteRef({
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
ref: `heads/${branch}`
});
if (pullRequest.head.repo === null ||
pullRequest.head.repo.full_name ===
`${github_1.context.repo.owner}/${github_1.context.repo.repo}`) {
issueLogger.info(`Deleting the branch "${logger_service_1.LoggerService.cyan(branch)}" from closed $$type`);
try {
this._consumeIssueOperation(issue);
(_a = this.statistics) === null || _a === void 0 ? void 0 : _a.incrementDeletedBranchesCount();
if (!this.options.debugOnly) {
yield this.client.rest.git.deleteRef({
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
ref: `heads/${branch}`
});
}
}
catch (error) {
issueLogger.error(`Error when deleting the branch "${logger_service_1.LoggerService.cyan(branch)}" from $$type: ${error.message}`);
}
}
catch (error) {
issueLogger.error(`Error when deleting the branch "${logger_service_1.LoggerService.cyan(branch)}" from $$type: ${error.message}`);
else {
issueLogger.warning(`Deleting the branch "${logger_service_1.LoggerService.cyan(branch)}" has skipped because it belongs to other repo ${pullRequest.head.repo.full_name}`);
}
});
}

View File

@ -921,26 +921,41 @@ export class IssuesProcessor {
}
const branch = pullRequest.head.ref;
issueLogger.info(
`Deleting the branch "${LoggerService.cyan(branch)}" from closed $$type`
);
try {
this._consumeIssueOperation(issue);
this.statistics?.incrementDeletedBranchesCount();
if (
pullRequest.head.repo === null ||
pullRequest.head.repo.full_name ===
`${context.repo.owner}/${context.repo.repo}`
) {
issueLogger.info(
`Deleting the branch "${LoggerService.cyan(branch)}" from closed $$type`
);
if (!this.options.debugOnly) {
await this.client.rest.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `heads/${branch}`
});
try {
this._consumeIssueOperation(issue);
this.statistics?.incrementDeletedBranchesCount();
if (!this.options.debugOnly) {
await this.client.rest.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `heads/${branch}`
});
}
} catch (error) {
issueLogger.error(
`Error when deleting the branch "${LoggerService.cyan(
branch
)}" from $$type: ${error.message}`
);
}
} catch (error) {
issueLogger.error(
`Error when deleting the branch "${LoggerService.cyan(
} else {
issueLogger.warning(
`Deleting the branch "${LoggerService.cyan(
branch
)}" from $$type: ${error.message}`
)}" has skipped because it belongs to other repo ${
pullRequest.head.repo.full_name
}`
);
}
}

View File

@ -2,6 +2,9 @@ export interface IPullRequest {
number: number;
head: {
ref: string;
repo: {
full_name: string;
} | null;
};
draft?: boolean;
}