pmr

Merge ~cjwatson/pmr:better-git-commit-messages into ~thomir-deactivatedaccount/pmr:master

Proposed by Colin Watson
Status: Merged
Approved by: Thomi Richards
Approved revision: 6bed5fe767ec24e57e122ccbd0703f9ba0283f33
Merged at revision: 6bed5fe767ec24e57e122ccbd0703f9ba0283f33
Proposed branch: ~cjwatson/pmr:better-git-commit-messages
Merge into: ~thomir-deactivatedaccount/pmr:master
Diff against target: 53 lines (+23/-1)
1 file modified
process-merge-requests (+23/-1)
Reviewer Review Type Date Requested Status
Thomi Richards Pending
Review via email: mp+305538@code.launchpad.net

Commit message

Produce nicer git commit messages

This avoids ugly "Merge commit '<hash>' into <merge-id>" messages, and
causes the commit_message field on merge proposals to mean something.
We now always create a merge commit, and construct a commit message that
includes the merge proposal ID, a shortened version of the repository
and path that match the titles of merge proposals in the Launchpad web
UI, and the commit_message field from the merge proposal. For example,
one might end up with:

  Merge #300000 from ~contributor/project:branch

  Rotate weasels instead of stoats

  Stoats object to being rotated, so rotate weasels instead. Unless
  otherwise specified, mustelid-rotation is through 180 degrees.

Description of the change

Produce nicer git commit messages

This avoids ugly "Merge commit '<hash>' into <merge-id>" messages, and
causes the commit_message field on merge proposals to mean something.
We now always create a merge commit, and construct a commit message that
includes the merge proposal ID, a shortened version of the repository
and path that match the titles of merge proposals in the Launchpad web
UI, and the commit_message field from the merge proposal. For example,
one might end up with:

  Merge #300000 from ~contributor/project:branch

  Rotate weasels instead of stoats

  Stoats object to being rotated, so rotate weasels instead. Unless
  otherwise specified, mustelid-rotation is through 180 degrees.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/process-merge-requests b/process-merge-requests
index 633086f..21b9d36 100755
--- a/process-merge-requests
+++ b/process-merge-requests
@@ -94,6 +94,21 @@ def get_ro_git_url(git_repository):
94 return git_repository.git_https_url94 return git_repository.git_https_url
9595
9696
97def get_git_identity(git_repository, git_path):
98 """Get the identity of a given Launchpad git reference.
99
100 This emulates Launchpad's internal GitRef.identity method, used to
101 display merge proposal titles.
102 """
103 shortened_path = git_repository.git_identity
104 if shortened_path.startswith('lp:'):
105 shortened_path = shortened_path[len('lp:'):]
106 branch_name = git_path
107 if branch_name.startswith('refs/heads/'):
108 branch_name = branch_name[len('refs/heads/'):]
109 return '{0}:{1}'.format(shortened_path, branch_name)
110
111
97def get_rw_bzr_url(bzr_branch):112def get_rw_bzr_url(bzr_branch):
98 """Get the read-write URL of a given launchpad bzr branch."""113 """Get the read-write URL of a given launchpad bzr branch."""
99 return 'bzr+ssh://bazaar.launchpad.net/{0}'.format(bzr_branch.unique_name)114 return 'bzr+ssh://bazaar.launchpad.net/{0}'.format(bzr_branch.unique_name)
@@ -143,10 +158,16 @@ def merge_git_proposal(branch_merge_proposal):
143 source_path = branch_merge_proposal.source_git_path158 source_path = branch_merge_proposal.source_git_path
144 # source_branch = source_path.split('/')[-1]159 # source_branch = source_path.split('/')[-1]
145 # source branch is not used, as we're relying on reviewed_revid160 # source branch is not used, as we're relying on reviewed_revid
161 source_identity = get_git_identity(
162 branch_merge_proposal.source_git_repository,
163 branch_merge_proposal.source_git_path)
146 reviewed_revid = branch_merge_proposal.reviewed_revid164 reviewed_revid = branch_merge_proposal.reviewed_revid
147 target_url = get_rw_git_url(branch_merge_proposal.target_git_repository)165 target_url = get_rw_git_url(branch_merge_proposal.target_git_repository)
148 target_path = branch_merge_proposal.target_git_path166 target_path = branch_merge_proposal.target_git_path
149 target_branch = target_path.split('/')[-1]167 target_branch = target_path.split('/')[-1]
168 commit_message = 'Merge #{0} from {1}'.format(merge_id, source_identity)
169 if branch_merge_proposal.commit_message is not None:
170 commit_message += '\n\n' + branch_merge_proposal.commit_message
150 _logger.info(_("Setting up git merge"))171 _logger.info(_("Setting up git merge"))
151 _logger.info(_(" - source: %s:%s"), source_url, source_path)172 _logger.info(_(" - source: %s:%s"), source_url, source_path)
152 _logger.info(_(" revision: %s"), reviewed_revid)173 _logger.info(_(" revision: %s"), reviewed_revid)
@@ -169,7 +190,8 @@ def merge_git_proposal(branch_merge_proposal):
169 return190 return
170 # Merge the branch191 # Merge the branch
171 try:192 try:
172 sh('git', 'merge', '--no-edit', reviewed_revid)193 sh('git', 'merge', '--no-ff', '--no-edit', '-m', commit_message,
194 reviewed_revid)
173 except subprocess.CalledProcessError:195 except subprocess.CalledProcessError:
174 branch_merge_proposal.createComment(196 branch_merge_proposal.createComment(
175 subject='I cannot merge this branch',197 subject='I cannot merge this branch',

Subscribers

People subscribed via source and target branches

to all changes: