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
1diff --git a/process-merge-requests b/process-merge-requests
2index 633086f..21b9d36 100755
3--- a/process-merge-requests
4+++ b/process-merge-requests
5@@ -94,6 +94,21 @@ def get_ro_git_url(git_repository):
6 return git_repository.git_https_url
7
8
9+def get_git_identity(git_repository, git_path):
10+ """Get the identity of a given Launchpad git reference.
11+
12+ This emulates Launchpad's internal GitRef.identity method, used to
13+ display merge proposal titles.
14+ """
15+ shortened_path = git_repository.git_identity
16+ if shortened_path.startswith('lp:'):
17+ shortened_path = shortened_path[len('lp:'):]
18+ branch_name = git_path
19+ if branch_name.startswith('refs/heads/'):
20+ branch_name = branch_name[len('refs/heads/'):]
21+ return '{0}:{1}'.format(shortened_path, branch_name)
22+
23+
24 def get_rw_bzr_url(bzr_branch):
25 """Get the read-write URL of a given launchpad bzr branch."""
26 return 'bzr+ssh://bazaar.launchpad.net/{0}'.format(bzr_branch.unique_name)
27@@ -143,10 +158,16 @@ def merge_git_proposal(branch_merge_proposal):
28 source_path = branch_merge_proposal.source_git_path
29 # source_branch = source_path.split('/')[-1]
30 # source branch is not used, as we're relying on reviewed_revid
31+ source_identity = get_git_identity(
32+ branch_merge_proposal.source_git_repository,
33+ branch_merge_proposal.source_git_path)
34 reviewed_revid = branch_merge_proposal.reviewed_revid
35 target_url = get_rw_git_url(branch_merge_proposal.target_git_repository)
36 target_path = branch_merge_proposal.target_git_path
37 target_branch = target_path.split('/')[-1]
38+ commit_message = 'Merge #{0} from {1}'.format(merge_id, source_identity)
39+ if branch_merge_proposal.commit_message is not None:
40+ commit_message += '\n\n' + branch_merge_proposal.commit_message
41 _logger.info(_("Setting up git merge"))
42 _logger.info(_(" - source: %s:%s"), source_url, source_path)
43 _logger.info(_(" revision: %s"), reviewed_revid)
44@@ -169,7 +190,8 @@ def merge_git_proposal(branch_merge_proposal):
45 return
46 # Merge the branch
47 try:
48- sh('git', 'merge', '--no-edit', reviewed_revid)
49+ sh('git', 'merge', '--no-ff', '--no-edit', '-m', commit_message,
50+ reviewed_revid)
51 except subprocess.CalledProcessError:
52 branch_merge_proposal.createComment(
53 subject='I cannot merge this branch',

Subscribers

People subscribed via source and target branches

to all changes: