Skip to content

Commit cc3e130

Browse files
meorphismeorphis
andauthored
do not hard reset next in release-please (#211)
* do not hard reset next in release-please * fix --------- Co-authored-by: meorphis <[email protected]>
1 parent 50cdd75 commit cc3e130

File tree

2 files changed

+0
-496
lines changed

2 files changed

+0
-496
lines changed

src/manifest.ts

Lines changed: 0 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import {
4141
ConfigurationError,
4242
isOctokitRequestError,
4343
isOctokitGraphqlResponseError,
44-
AggregateError,
4544
} from './errors';
4645
import {ManifestPlugin} from './plugin';
4746
import {
@@ -1405,15 +1404,6 @@ export class Manifest {
14051404
}
14061405
}
14071406

1408-
// try to re-align branches to ensure the next release pull request won't face git conflicts. In case of
1409-
// inconsistencies releases are still created but the command fails and won't force a re-alignment between a PR
1410-
// ref branch and base branch.
1411-
try {
1412-
await this.alignPullRequestsChangesBranch(pullRequests);
1413-
} catch (err) {
1414-
this.logger.error(err as {});
1415-
}
1416-
14171407
return createdReleases;
14181408
}
14191409

@@ -1443,125 +1433,6 @@ export class Manifest {
14431433
}
14441434
}
14451435

1446-
private async alignPullRequestsChangesBranch(pullRequests: PullRequest[]) {
1447-
const errors: Error[] = [];
1448-
for (const pr of pullRequests) {
1449-
try {
1450-
await this.alignPullRequestChangesBranch(pr);
1451-
} catch (err: unknown) {
1452-
errors.push(err as Error);
1453-
}
1454-
}
1455-
if (errors.length > 0) {
1456-
throw new AggregateError(
1457-
errors,
1458-
'Errors when aligning pull requests branches'
1459-
);
1460-
}
1461-
}
1462-
1463-
private async alignPullRequestChangesBranch(pr: PullRequest) {
1464-
const branchName = BranchName.parse(pr.headBranchName);
1465-
1466-
// we only care about pull requests with an associated changes-branch
1467-
if (!branchName?.changesBranch) {
1468-
return;
1469-
}
1470-
this.logger.info(
1471-
`Aligning branches for PR #${pr.number}, changes branch ${branchName.changesBranch} to be aligned with ${this.targetBranch}`
1472-
);
1473-
1474-
let safeToRealign = false;
1475-
1476-
try {
1477-
this.logger.debug(
1478-
`Checking if PR commits are in sync with '${branchName.changesBranch}'...`
1479-
);
1480-
if (
1481-
await this.github.isBranchSyncedWithPullRequestCommits(
1482-
branchName.changesBranch,
1483-
pr
1484-
)
1485-
) {
1486-
this.logger.debug(
1487-
'PR commits and changes branch in sync, safe to re-align'
1488-
);
1489-
safeToRealign = true;
1490-
}
1491-
} catch (err: unknown) {
1492-
// if a branch of commit cannot be found it is likely the PR commits information aren't in a reliable state, in
1493-
// this case just ignore and continue with the next check
1494-
if (isOctokitRequestError(err) && err.status === 404) {
1495-
this.logger.debug(
1496-
`Could not compare commits from PR and '${branchName.changesBranch}' due to a branch or commit not found. Continue with the next check`
1497-
);
1498-
} else {
1499-
throw err;
1500-
}
1501-
}
1502-
1503-
// then check if changes-branch has already been synced with the base branch, in which case we don't need to do
1504-
// anything
1505-
if (
1506-
!safeToRealign &&
1507-
(await this.github.isBranchASyncedWithB(
1508-
branchName.changesBranch,
1509-
this.targetBranch
1510-
))
1511-
) {
1512-
this.logger.debug(
1513-
`Checking if ${branchName.changesBranch} is synced with ${this.targetBranch}...`
1514-
);
1515-
this.logger.debug('Branches already in sync, no need to re-align');
1516-
return;
1517-
}
1518-
1519-
if (!safeToRealign) {
1520-
throw new Error(
1521-
`Branch '${branchName.changesBranch}' cannot be safely re-aligned with '${this.targetBranch}', and will likely result in git conflicts when the next release PR is created. Hint: compare branches '${pr.headBranchName}', '${branchName.changesBranch}', and '${this.targetBranch}' for inconsistencies`
1522-
);
1523-
}
1524-
1525-
await this.github.alignBranchWithAnother(
1526-
branchName.changesBranch,
1527-
this.targetBranch
1528-
);
1529-
1530-
// updating git branches isn't always instant and can take a bit of time to propagate throughout github systems,
1531-
// it is safer to wait a little bit before doing anything else
1532-
const version = PullRequestTitle.parse(
1533-
pr.title,
1534-
this.repositoryConfig[branchName.getComponent() || '.']
1535-
?.pullRequestTitlePattern,
1536-
this.logger
1537-
)?.getVersion();
1538-
if (!version) {
1539-
this.logger.warn(
1540-
`PR #${pr.number} title missing a version number: '${pr.title}'`
1541-
);
1542-
return;
1543-
}
1544-
await this.github.waitForFileToBeUpToDateOnBranch({
1545-
branch: branchName.changesBranch,
1546-
filePath: this.manifestPath,
1547-
checkFileStatus: fileContent => {
1548-
const json = JSON.parse(fileContent) as Record<string, unknown>;
1549-
if (!json) {
1550-
return false;
1551-
}
1552-
const path = branchName.getComponent() || '.';
1553-
const val = json[path];
1554-
if (typeof val !== 'string') {
1555-
this.logger.error(
1556-
`Value of manifest file ${this.manifestPath} at key '${path}' was not a string. value=${val}`
1557-
);
1558-
return false;
1559-
}
1560-
return val === version.toString();
1561-
},
1562-
});
1563-
}
1564-
15651436
private async createReleasesForPullRequest(
15661437
releases: CandidateRelease[],
15671438
pullRequest: PullRequest

0 commit comments

Comments
 (0)