Skip to content

Commit

Permalink
feat: make pr merge commit message more informative
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoechegut committed Mar 20, 2024
1 parent 2e06e3f commit 37ba91b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
git-workspace*
dist
dist
.idea
2 changes: 1 addition & 1 deletion __tests__/assertHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function assertBranchCreated(
function assertCommitsMerged(mockMergeCommit: jest.MockInstance<any, any>, commits: string[]) {
expect(mockMergeCommit).toHaveBeenCalledTimes(commits.length);
commits.forEach(commit =>
expect(mockMergeCommit).toHaveBeenCalledWith(commit, "merged by merge-pr-to-branch")
expect(mockMergeCommit).toHaveBeenCalledWith(commit, expect.stringMatching(/^merged .* by merge-pr-to-branch/))
);
}
function assertHardReset(mockResetHard: jest.MockInstance<any, any>, commit: string) {
Expand Down
2 changes: 1 addition & 1 deletion install/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: deliveroo/merge-pr-to-branch@v5
- uses: deliveroo/merge-pr-to-branch@v6
19 changes: 13 additions & 6 deletions src/mergeDeployablePullRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const processMergeResults = async (
}
)
);

const getMergablePullRequests = async (
github: GithubApiManager,
baseBranch: string,
Expand Down Expand Up @@ -159,7 +160,7 @@ async function mergePullRequest(
targetBranch: string
): Promise<mergePullRequestResult> {
try {
const message = await mergeCommit(git, targetBranch, pullRequest.data.head.sha);
const message = await mergeCommit(git, targetBranch, pullRequest);
return { pullRequest, message };
} catch (error) {
const errorMessage = `Skipped PR due to merge error: \n${JSON.stringify(
Expand Down Expand Up @@ -191,15 +192,21 @@ export const getBaseBranch = (context: githubContext, payload: githubPayload) =>
return getBranchFromRef(payload.ref);
}
};

export const hasLabel = (labels: (string | { name: string })[], label: string) =>
labels.some(l => (l instanceof Object ? l.name === label : l === label));
export const mergeCommit = async (git: GitCommandManager, targetBranch: string, ref: string) => {
const mergeMessage = createCommitMessage("merged");
return await git.mergeCommit(ref, mergeMessage).then(
() => `Successfully merged '${ref}' to '${targetBranch}'.`,

export const mergeCommit = async (git: GitCommandManager, targetBranch: string,
pullRequest: Github.Response<Github.PullsGetResponse>,) => {
const commitSha = pullRequest.data.head.sha
const prNumber = pullRequest.data.number;
const baseBranch = pullRequest.data.head.ref;
const mergeMessage = createCommitMessage(`merged '${baseBranch}' (#${prNumber})`);
return await git.mergeCommit(commitSha, mergeMessage).then(
() => `Successfully merged '${commitSha}' to '${targetBranch}'.`,
error => {
throw new Error(
`Merge '${ref}' to '${targetBranch}' failed: \n${JSON.stringify(serializeError(error))}`
`Merge '${commitSha}' to '${targetBranch}' failed: \n${JSON.stringify(serializeError(error))}`
);
}
);
Expand Down

0 comments on commit 37ba91b

Please sign in to comment.