Skip to content

Commit a45413e

Browse files
committed
Revert "feat(ng-dev): add conditional autosquash merge strategy"
This reverts commit 95499f4.
1 parent 95499f4 commit a45413e

File tree

6 files changed

+23
-119
lines changed

6 files changed

+23
-119
lines changed

.ng-dev/pull-request.mts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ import {PullRequestConfig} from '../ng-dev/pr/config/index.js';
22

33
/** Configuration for interacting with pull requests in the repo. */
44
export const pullRequest: PullRequestConfig = {
5-
githubApiMerge: {
6-
default: 'rebase',
7-
labels: [{pattern: 'merge: squash commits', method: 'squash'}],
8-
},
9-
conditionalAutosquashMerge: true,
5+
githubApiMerge: false,
106
requiredStatuses: [{name: 'test', type: 'check'}],
117

128
// Disable target labeling in the dev-infra repo as we don't have

ng-dev/pr/config/index.ts

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export interface GithubApiMergeStrategyConfig {
2323
}
2424

2525
/** Configuration for the merge script. */
26-
export type PullRequestConfig = {
26+
export interface PullRequestConfig {
2727
/**
2828
* Configuration for the upstream remote. All of these options are optional as
2929
* defaults are provided by the common dev-infra github configuration.
@@ -63,25 +63,7 @@ export type PullRequestConfig = {
6363
* follow the canonical branching/versioning.
6464
*/
6565
__noTargetLabeling?: boolean;
66-
} & {
67-
/**
68-
* Whether pull requests should be merged using a conditional autosquash strategy.
69-
* If a pull request contains fixup or squash commits, the autosquash strategy
70-
* will be used. Otherwise, the Github API merge strategy will be used.
71-
*/
72-
conditionalAutosquashMerge?: boolean;
73-
74-
/**
75-
* The configuration for merging pull requests using the Github API.
76-
*
77-
* This strategy is used as a fallback for the `conditionalAutosquashMerge` strategy,
78-
* when a pull request does not contain any fixup or squash commits.
79-
*
80-
* This can be enabled if projects want to have their pull requests show up as
81-
* `Merged` in the Github UI.
82-
*/
83-
githubApiMerge: GithubApiMergeStrategyConfig;
84-
};
66+
}
8567

8668
/** Loads and validates the merge configuration. */
8769
export function assertValidPullRequestConfig<T extends NgDevConfig>(
@@ -94,18 +76,10 @@ export function assertValidPullRequestConfig<T extends NgDevConfig>(
9476
);
9577
}
9678

97-
const {conditionalAutosquashMerge, githubApiMerge} = config.pullRequest;
98-
if (githubApiMerge === undefined) {
79+
if (config.pullRequest.githubApiMerge === undefined) {
9980
errors.push('No explicit choice of merge strategy. Please set `githubApiMerge`.');
10081
}
10182

102-
if (conditionalAutosquashMerge && !githubApiMerge) {
103-
errors.push(
104-
'`conditionalAutosquashMerge` requires a GitHub API merge strategy to inspect commit history. ' +
105-
'Please configure `githubApiMerge` or disable `conditionalAutosquashMerge`.',
106-
);
107-
}
108-
10983
if (errors.length) {
11084
throw new ConfigValidationError('Invalid `pullRequest` configuration', errors);
11185
}

ng-dev/pr/merge/merge-tool.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
import {loadAndValidatePullRequest, PullRequest} from './pull-request.js';
2020
import {GithubApiMergeStrategy} from './strategies/api-merge.js';
2121
import {AutosquashMergeStrategy} from './strategies/autosquash-merge.js';
22-
import {ConditionalAutosquashMergeStrategy} from './strategies/conditional-autosquash-merge.js';
2322
import {GithubConfig, NgDevConfig} from '../../utils/config.js';
2423
import {assertValidReleaseConfig} from '../../release/config/index.js';
2524
import {
@@ -140,20 +139,9 @@ export class MergeTool {
140139
throw new UserAbortedMergeToolError();
141140
}
142141

143-
let strategy:
144-
| AutosquashMergeStrategy
145-
| ConditionalAutosquashMergeStrategy
146-
| GithubApiMergeStrategy;
147-
148-
const {conditionalAutosquashMerge, githubApiMerge} = this.config.pullRequest;
149-
150-
if (conditionalAutosquashMerge) {
151-
strategy = new ConditionalAutosquashMergeStrategy(this.git, githubApiMerge);
152-
} else if (githubApiMerge) {
153-
strategy = new GithubApiMergeStrategy(this.git, githubApiMerge);
154-
} else {
155-
strategy = new AutosquashMergeStrategy(this.git);
156-
}
142+
const strategy = this.config.pullRequest.githubApiMerge
143+
? new GithubApiMergeStrategy(this.git, this.config.pullRequest.githubApiMerge)
144+
: new AutosquashMergeStrategy(this.git);
157145

158146
// Branch or revision that is currently checked out so that we can switch back to
159147
// it once the pull request has been merged.

ng-dev/pr/merge/strategies/api-merge.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import {RestEndpointMethodTypes} from '@octokit/plugin-rest-endpoint-methods';
1010

11+
import {parseCommitMessage} from '../../../commit-message/parse.js';
1112
import {AuthenticatedGitClient} from '../../../utils/git/authenticated-git-client.js';
1213
import {GithubApiMergeMethod, GithubApiMergeStrategyConfig} from '../../config/index.js';
1314
import {PullRequest} from '../pull-request.js';
@@ -51,7 +52,7 @@ export class GithubApiMergeStrategy extends MergeStrategy {
5152
*/
5253
override async merge(pullRequest: PullRequest): Promise<void> {
5354
const {githubTargetBranch, prNumber, needsCommitMessageFixup, targetBranches} = pullRequest;
54-
const method = this.getMergeActionFromPullRequest(pullRequest);
55+
const method = this._getMergeActionFromPullRequest(pullRequest);
5556
const cherryPickTargetBranches = targetBranches.filter((b) => b !== githubTargetBranch);
5657

5758
const mergeOptions: OctokitMergeParams = {
@@ -194,7 +195,10 @@ export class GithubApiMergeStrategy extends MergeStrategy {
194195
* behavior here so that we have a default commit message that can be fixed up.
195196
*/
196197
private async _getDefaultSquashCommitMessage(pullRequest: PullRequest): Promise<string> {
197-
const commits = await this.getPullRequestCommits(pullRequest);
198+
const commits = (await this._getPullRequestCommitMessages(pullRequest)).map((message) => ({
199+
message,
200+
parsed: parseCommitMessage(message),
201+
}));
198202
const messageBase = `${pullRequest.title}${COMMIT_HEADER_SEPARATOR}`;
199203
if (commits.length <= 1) {
200204
return `${messageBase}${commits[0].parsed.body}`;
@@ -203,8 +207,17 @@ export class GithubApiMergeStrategy extends MergeStrategy {
203207
return `${messageBase}${joinedMessages}`;
204208
}
205209

210+
/** Gets all commit messages of commits in the pull request. */
211+
private async _getPullRequestCommitMessages({prNumber}: PullRequest) {
212+
const allCommits = await this.git.github.paginate(this.git.github.pulls.listCommits, {
213+
...this.git.remoteParams,
214+
pull_number: prNumber,
215+
});
216+
return allCommits.map(({commit}) => commit.message);
217+
}
218+
206219
/** Determines the merge action from the given pull request. */
207-
getMergeActionFromPullRequest({labels}: PullRequest): GithubApiMergeMethod {
220+
private _getMergeActionFromPullRequest({labels}: PullRequest): GithubApiMergeMethod {
208221
if (this._config.labels) {
209222
const matchingLabel = this._config.labels.find(({pattern}) => labels.includes(pattern));
210223
if (matchingLabel !== undefined) {

ng-dev/pr/merge/strategies/conditional-autosquash-merge.ts

Lines changed: 0 additions & 48 deletions
This file was deleted.

ng-dev/pr/merge/strategies/strategy.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Commit, parseCommitMessage} from '../../../commit-message/parse.js';
109
import {AuthenticatedGitClient} from '../../../utils/git/authenticated-git-client.js';
1110
import {
1211
FatalMergeToolError,
@@ -201,22 +200,4 @@ export abstract class MergeStrategy {
201200
throw new MergeConflictsFatalError(failedBranches);
202201
}
203202
}
204-
205-
/** Gets all commit messages of commits in the pull request. */
206-
protected async getPullRequestCommits({prNumber}: PullRequest): Promise<
207-
{
208-
message: string;
209-
parsed: Commit;
210-
}[]
211-
> {
212-
const allCommits = await this.git.github.paginate(this.git.github.pulls.listCommits, {
213-
...this.git.remoteParams,
214-
pull_number: prNumber,
215-
});
216-
217-
return allCommits.map(({commit: {message}}) => ({
218-
message,
219-
parsed: parseCommitMessage(message),
220-
}));
221-
}
222203
}

0 commit comments

Comments
 (0)