Skip to content

Commit 0512a5b

Browse files
committed
fix(ng-dev): improve failure message for repository rule violation
When a merge fails due to a repository rule violation, we provide a failure message pointing to our group membership based access for merging.
1 parent 1eab387 commit 0512a5b

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

.github/local-actions/branch-manager/main.js

Lines changed: 10 additions & 2 deletions
Large diffs are not rendered by default.

ng-dev/pr/merge/merge-pull-request.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ export async function mergePullRequest(prNumber: number, flags: PullRequestMerge
6666
Log.warn(`You can generate a token here: ${GITHUB_TOKEN_GENERATE_URL}`);
6767
return false;
6868
}
69+
// Catch errors to the Github API for repository rule violations. We want to
70+
// exit the script with a better explanation of the error.
71+
if (
72+
isGithubApiError(e) &&
73+
e.status === 405 &&
74+
e.message.startsWith('Repository rule violations found')
75+
) {
76+
Log.error(' ✘ Repository Rule Violation. This typically indicates that you are not');
77+
Log.error(' currently a member of the expected group for merge permissions in this');
78+
Log.error(' repository. Have you been placed in the expected caretaking group?');
79+
Log.debug('Github API request failed: ' + bold(e.message));
80+
return false;
81+
}
6982
if (isGithubApiError(e)) {
7083
Log.error('Github API request failed: ' + bold(e.message));
7184
return false;

ng-dev/utils/git/github.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {Octokit} from '@octokit/rest';
1212
import {RequestParameters} from '@octokit/types';
1313
import {RequestError} from '@octokit/request-error';
1414
import {query} from 'typed-graphqlify';
15+
import {Log} from '../logging';
1516

1617
/**
1718
* An object representation of a Graphql Query to be used as a response type and
@@ -30,7 +31,17 @@ export interface GithubRepo {
3031
/** A Github client for interacting with the Github APIs. */
3132
export class GithubClient {
3233
/** The octokit instance actually performing API requests. */
33-
protected _octokit: Octokit = new Octokit({...this._octokitOptions});
34+
protected _octokit: Octokit = new Octokit({
35+
// Move all default octokit logging into debug. We prefer handle all of the logging exposed
36+
// to user's from Github ourselves.
37+
log: {
38+
debug: Log.debug,
39+
error: Log.debug,
40+
info: Log.debug,
41+
warn: Log.debug,
42+
},
43+
...this._octokitOptions,
44+
});
3445

3546
readonly pulls: Octokit['pulls'] = this._octokit.pulls;
3647
readonly orgs: Octokit['orgs'] = this._octokit.orgs;

0 commit comments

Comments
 (0)