vcssync: stop defining GitHub username (bug 1358312); r?glob draft
authorGregory Szorc <gps@mozilla.com>
Thu, 20 Apr 2017 16:42:17 -0700
changeset 10835 417d212ab825cf23d19aca8f2bed9218f47dcd8c
parent 10826 49e4453aabdf227a4ad363fa3922f9cc60fa1464
child 10836 7239a86ab53d93a595c28bc69039b49c9d58b9ae
push id1636
push userbmo:gps@mozilla.com
push dateFri, 21 Apr 2017 00:31:50 +0000
reviewersglob
bugs1358312
vcssync: stop defining GitHub username (bug 1358312); r?glob As part of refactoring code using github3 in a subsequent commit, I realized that a username is not needed when using API tokens. The code requires a username+password OR a token. Unless the password is defined, the username argument is ignored. So, stop defining and using a GitHub username value in the code and in automation configs. MozReview-Commit-ID: D3haUp0AyZx
ansible/roles/vcs-sync/templates/servo-sync.env.j2
ansible/vcssync-deploy.yml
vcssync/mozvcssync/cli.py
vcssync/mozvcssync/gitrewrite/__init__.py
--- a/ansible/roles/vcs-sync/templates/servo-sync.env.j2
+++ b/ansible/roles/vcs-sync/templates/servo-sync.env.j2
@@ -1,9 +1,8 @@
-GITHUB_USERNAME={{ servo_github_username | mandatory }}
 GITHUB_TOKEN={{ servo_github_token | mandatory }}
 
 LINEAR_GIT_SOURCE_URL={{ servo_linear_git_source_url | mandatory }}
 LINEAR_GIT_PUSH_URL={{ servo_linear_git_push_url | mandatory }}
 LINEAR_HG_PUSH_URL={{ servo_linear_hg_push_url | mandatory }}
 
 OVERLAY_SOURCE_URL={{ servo_overlay_source_url | mandatory }}
 OVERLAY_DEST_URL={{ servo_overlay_dest_url | mandatory }}
--- a/ansible/vcssync-deploy.yml
+++ b/ansible/vcssync-deploy.yml
@@ -17,17 +17,16 @@
       register: secrets
 
     # Ansible's variable interpolation behavior is crazy and this ugly redundancy
     # parsing the YAML is the only way gps could get this to work.
     - name: set fact with secrets
       set_fact:
         pulse_userid: "{{ (secrets.stdout | from_yaml).pulse_userid | mandatory }}"
         pulse_password: "{{ (secrets.stdout | from_yaml).pulse_password | mandatory }}"
-        servo_github_username: "{{ (secrets.stdout | from_yaml).servo_github_username | mandatory }}"
         servo_github_token: "{{ (secrets.stdout | from_yaml).servo_github_token | mandatory }}"
         servo_github_ssh_key: "{{ (secrets.stdout | from_yaml).servo_github_ssh_key | mandatory }}"
         servo_hgmo_ssh_key: "{{ (secrets.stdout | from_yaml).servo_hgmo_ssh_key | mandatory }}"
         servo_hgmo_ssh_user: "{{ (secrets.stdout | from_yaml).servo_hgmo_ssh_user | mandatory }}"
 
   roles:
     - common
     - vcs-sync
--- a/vcssync/mozvcssync/cli.py
+++ b/vcssync/mozvcssync/cli.py
@@ -56,39 +56,37 @@ LINEARIZE_GIT_ARGS = [
                                              'use-committer'},
                                     help='What to do with committer field in'
                                          'Git commits')),
     (('--author-map',), dict(help='File containing mapping of old to new '
                                   'commit author/committer values')),
     (('--use-p2-author',), dict(action='store_true',
                                 help='Use the author of the 2nd parent for '
                                      'merge commits')),
-    (('--github-username',), dict(help='Username to use for GitHub API '
-                                       'requests')),
     (('--github-token',), dict(help='GitHub API token to use for GitHub API '
                                     'requests')),
 ]
 
 
 def get_commit_rewriter_kwargs(args):
     """Obtain keyword arguments to pass to ``commit_metadata_rewriter()``"""
     kwargs = {}
 
     # Credentials are sensitive. Allow them to come from environment,
     # which isn't exposed in e.g. `ps`.
-    for env in ('GITHUB_USERNAME', 'GITHUB_TOKEN'):
+    for env in ('GITHUB_TOKEN',):
         v = os.environ.get(env)
         if v is not None:
             kwargs[env.lower()] = v
 
     for k in ('summary_prefix', 'reviewable_key',
               'remove_reviewable', 'source_repo_key',
               'source_revision_key', 'normalize_github_merge_message',
               'committer_action', 'use_p2_author',
-              'github_username', 'github_token'):
+              'github_token'):
         v = getattr(args, k)
         if v is not None:
             kwargs[k] = v
 
     if args.author_map:
         author_map = {}
         with open(args.author_map, 'rb') as fh:
             for line in fh:
--- a/vcssync/mozvcssync/gitrewrite/__init__.py
+++ b/vcssync/mozvcssync/gitrewrite/__init__.py
@@ -305,17 +305,16 @@ def commit_metadata_rewriter(
         remove_reviewable=False,
         normalize_github_merge_message=False,
         source_repo_key=None,
         source_repo=None,
         source_revision_key=None,
         committer_action='keep',
         author_map=None,
         use_p2_author=False,
-        github_username=None,
         github_token=None):
     """Obtain a function used to rewrite Git commit object metadata.
 
     The returned function is called with 2 arguments: the old and new Git commit
     objects. The function is expected to mutate the new Git commit object.
 
     The function is attached to a ``dulwich.repo.Repo`` instance and a set of
     behavioral options  defined via arguments. Those arguments are as follows:
@@ -353,19 +352,18 @@ def commit_metadata_rewriter(
     """
     if committer_action not in ('keep', 'use-author', 'use-committer'):
         raise ValueError('committer_action must be one of keep, use-author, '
                          'or use-committer')
 
     author_map = author_map or {}
 
     github_client = None
-    if github_username and github_token:
-        github_client = github3.login(username=github_username,
-                                      token=github_token)
+    if github_token:
+        github_client = github3.login(token=github_token)
 
     github_org, github_repo = None, None
     github_cache_dir = os.path.join(repo.path, 'github-cache')
 
     if source_repo and source_repo.startswith(b'https://github.com/'):
         orgrepo = source_repo[len(b'https://github.com/'):]
         github_org, github_repo = orgrepo.split(b'/')