airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlo...@apache.org
Subject [4/8] incubator-airflow git commit: [AIRFLOW-302] Improve default squash commit message
Date Tue, 12 Jul 2016 14:55:39 GMT
[AIRFLOW-302] Improve default squash commit message

Previously, we always used the PR title as the squash commit subject.
Now, if the squash contains only one commit, then we use the commit
message for the squash commit message. If the squash contains more than
one commit, we default to the old behavior (using the PR title). We
still ask if the user wants to include the PR body, but we only ask if
they want to include the individual commits if there was more than one.


Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/f3a05d47
Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/f3a05d47
Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/f3a05d47

Branch: refs/heads/master
Commit: f3a05d4733acb2634ab49fa6bc1d83cf55289569
Parents: bfd2cfc
Author: jlowin <jlowin@users.noreply.github.com>
Authored: Thu Jun 30 20:18:04 2016 -0400
Committer: jlowin <jlowin@users.noreply.github.com>
Committed: Thu Jun 30 20:40:37 2016 -0400

----------------------------------------------------------------------
 dev/airflow-pr | 103 ++++++++++++++++++++++++++++++++--------------------
 1 file changed, 63 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/f3a05d47/dev/airflow-pr
----------------------------------------------------------------------
diff --git a/dev/airflow-pr b/dev/airflow-pr
index 3650dcb..e3cb3d3 100755
--- a/dev/airflow-pr
+++ b/dev/airflow-pr
@@ -184,41 +184,32 @@ def merge_pr(pr_num, target_ref, title, body, pr_repo_desc, local):
     merge_message_flags = []
 
     if squash:
-        commit_authors = run_cmd(
-            ['git', 'log', 'HEAD..{}'.format(pr_branch_name),
-             '--pretty=format:%an <%ae>'], echo_cmd=False).split("\n")
-        distinct_authors = sorted(
-            set(commit_authors),
-            key=lambda x: commit_authors.count(x),
-            reverse=True)
-        primary_author = click.prompt(
-            click.style(
-                'Enter the primary author in the format of \"name <email>\"',
-                fg='blue', bold=True),
-            default=distinct_authors[0])
-        if primary_author == "":
-            primary_author = distinct_authors[0]
-
-        commits = run_cmd(
-            ['git', 'log', 'HEAD..%s' % pr_branch_name,
-             '--pretty=format:%h [%an] %s'], echo_cmd=False).split("\n\n")
-
-        # -- set authors and add authors to commit message
-        authors = "\n".join(["Author: %s" % a for a in distinct_authors])
-        merge_message_flags.append('--author="{}"'.format(primary_author))
-
-        # -- Add PR to commit message
-        merge_message_flags.extend(["-m", title])
-        msg = click.style(
-            'Would you like to include the PR body in the squash '
-            'commit message?',
-            fg='blue', bold=True)
-        if body and click.confirm(msg, default=False, prompt_suffix=''):
-            # We remove @ symbols from the body to avoid triggering e-mails
-            # to people every time someone creates a public fork of Airflow.
-            merge_message_flags += ["-m", body.replace("@", "")]
-
 
+        # -- create commit message subject
+        # if there is only one commit, take the squash commit message from it
+        if len(pr_commits) == 1:
+            click.echo(click.style(
+                'This squash contains only one commit, so we will use its\n'
+                'commit message for the squash commit message. You will have\n'
+                'an opportunity to edit it later.', bold=True))
+            commit_message = pr_commits[0]['commit']['message']
+            merge_message_flags.extend(["-m", commit_message])
+        # if there is are multiple commits, take the squash commit message from
+        # the PR title
+        else:
+            click.echo(click.style(
+                'This squash contains more than one commit, so we will use\n'
+                'the PR title as the squash commit subject. You will have an\n'
+                'opportunity to edit it later.', bold=True))
+            merge_message_flags.extend(["-m", title])
+
+        commit_subject = merge_message_flags[-1].split('\n')[0]
+        if not re.findall("AIRFLOW-[0-9]{1,6}", commit_subject):
+            click.echo(click.style(
+                'Note that the commit subject does not reference a '
+                'JIRA issue!', fg='red', bold=True))
+
+        # -- Note conflicts
         if had_conflicts:
             committer_name = run_cmd(
                 "git config --get user.name", echo_cmd=False)
@@ -229,14 +220,26 @@ def merge_pr(pr_num, target_ref, title, body, pr_repo_desc, local):
                 'Committer: %s <%s>' % (committer_name, committer_email))
             merge_message_flags.extend(["-m", message])
 
-        # -- add individual commit messages to squash commit
+        # -- Add PR body to commit message
         msg = click.style(
-            'Would you like to include the individual commit messages '
-            'in the squash commit message?',
+            'Would you like to include the PR body in the squash '
+            'commit message?',
             fg='blue', bold=True)
-        if pr_commits and click.confirm(msg, default=True, prompt_suffix=''):
-            for commit in pr_commits:
-                merge_message_flags.extend(['-m', commit['commit']['message']])
+        if body and click.confirm(msg, default=False, prompt_suffix=''):
+            # We remove @ symbols from the body to avoid triggering e-mails
+            # to people every time someone creates a public fork of Airflow.
+            merge_message_flags += ["-m", body.replace("@", "")]
+
+        # -- add individual commit messages to squash commit
+        if len(pr_commits) > 1:
+            m = click.style(
+                'Would you like to include the individual commit messages '
+                'in the squash commit message?',
+                fg='blue', bold=True)
+            if pr_commits and click.confirm(m, default=True, prompt_suffix=''):
+                for commit in pr_commits:
+                    merge_message_flags.extend(
+                        ['-m', commit['commit']['message']])
 
         # The string "Closes #%s" string is required for GitHub to correctly
         # close the PR. GitHub will mark the PR as closed, not merged
@@ -244,6 +247,26 @@ def merge_pr(pr_num, target_ref, title, body, pr_repo_desc, local):
         merge_message_flags.extend(["-m", "{} from {}".format(
             close_msg.capitalize(), pr_repo_desc)])
 
+        # -- set authors and add authors to commit message
+        commit_authors = run_cmd(
+            ['git', 'log', 'HEAD..{}'.format(pr_branch_name),
+             '--pretty=format:%an <%ae>'], echo_cmd=False).split("\n")
+        distinct_authors = sorted(
+            set(commit_authors),
+            key=lambda x: commit_authors.count(x),
+            reverse=True)
+        primary_author = click.prompt(
+            click.style(
+                'Enter the primary author in the format of \"name <email>\"',
+                fg='blue', bold=True),
+            default=distinct_authors[0])
+        if primary_author == "":
+            primary_author = distinct_authors[0]
+
+        authors = "\n".join(["Author: %s" % a for a in distinct_authors])
+        merge_message_flags.append('--author="{}"'.format(primary_author))
+
+
     else:
         # This will mark the PR as merged
         merge_message_flags.extend([


Mime
View raw message