From bd3f53d0a4497eb6b15167595d399241195d76a9 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 7 May 2019 10:29:18 +0200 Subject: [PATCH 01/13] Replace .netrc support by git credential --- README.rst | 29 ++++++++---------- git_pull_request/__init__.py | 59 +++++++++++++++++------------------- 2 files changed, 41 insertions(+), 47 deletions(-) diff --git a/README.rst b/README.rst index 1b51771..182a891 100644 --- a/README.rst +++ b/README.rst @@ -27,20 +27,6 @@ Although it might not be up to date with the `latest code on GitHub `_:: - - machine github.com login jd password f00b4r - -For Pagure, you need to create an API key by visiting your `settings `_ -and requesting the `Fork a project` and `Modify an existing project` ACLs:: - - machine pagure.io login tristanc password $your-api-token - -Note: since credentials are stored in plain text, you should encrypt your `$HOME` -directory to improve security. - Once you've made your commits into a branch, just type:: git pull-request @@ -60,6 +46,16 @@ been opened for your current working branch. Workflow advice =============== + +Caching Credentials +------------------- + +GitHub has a good documentation about using `git credential +`_. + +Creating Branches +----------------- + When sending pull-requests, it's preferable to do so from your own branch. You can create your own branch from `master` by doing:: @@ -86,8 +82,9 @@ Difference with hub The wrapper `hub`_ provides `hub fork` and `hub pull-request` as command line tools to fork and create pull-requests. -Unfortunately, it's hard to combine these tools in an automated implementation for a -complete workflow. +Unfortunately, it's hard to combine these tools in an automated implementation for a +complete workflow. + For example: If you need to update your pull-request, there's no way to identify existing pull requests, so calling `hub pull-request` would just open a new pull-request. diff --git a/git_pull_request/__init__.py b/git_pull_request/__init__.py index f960de3..e44b61a 100644 --- a/git_pull_request/__init__.py +++ b/git_pull_request/__init__.py @@ -16,7 +16,6 @@ import glob import itertools import logging -import netrc import operator import os import shutil @@ -50,29 +49,29 @@ def _run_shell_command(cmd, output=None, raise_on_error=True): return out[0].strip().decode() -def get_login_password(site_name="github.com", - netrc_file="~/.netrc", - git_credential_file="~/.git-credentials"): - """Read a .netrc file and return login/password for LWN.""" - try: - n = netrc.netrc(os.path.expanduser(netrc_file)) - except OSError: - pass - else: - if site_name in n.hosts: - return n.hosts[site_name][0], n.hosts[site_name][2] - - try: - with open(os.path.expanduser(git_credential_file)) as f: - for line in f: - parsed = parse.urlparse(line.strip()) - if parsed.hostname == site_name: - return (parse.unquote(parsed.username), - parse.unquote(parsed.password)) - except OSError: - pass - - return None, None +def get_login_password(protocol="https", host="github.com"): + """Get login/password from git credential.""" + subp = subprocess.Popen(["git", "credential", "fill"], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE) + # TODO add path support + request = "protocol={}\nhost={}\n".format(protocol, host).encode() + username = None + password = None + stdout, stderr = subp.communicate(input=request) + ret = subp.wait() + if ret != 0: + LOG.error("git credential returned exited with status %d", ret) + return None, None + for line in stdout.split(b'\n'): + key, _, value = line.partition(b"=") + if key == b"username": + username = value.decode() + elif key == b"password": + password = value.decode() + if username and password: + break + return username, password def git_remote_matching_url(url): @@ -257,14 +256,12 @@ def git_pull_request(target_remote=None, target_branch=None, LOG.debug("%s user and repository to fork: %s/%s on %s", hosttype.capitalize(), user_to_fork, reponame_to_fork, hostname) - user, password = get_login_password(hostname) - if not user or not password: + user, password = get_login_password(host=hostname) + if not user and not password: LOG.critical( - "Unable to find your GitHub credentials for %s.\n" - "Make sure you have a line like this in your ~/.netrc file:\n" - "machine %s login password , " - "or use git store credentials", - hostname, hostname + "Unable to find your credentials for %s.\n" + "Make sure you have a git credential working.", + hostname, ) return 35 From 42baa0b846111bc4773d283e18036e3bbe3fe28b Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 7 May 2019 14:23:46 +0200 Subject: [PATCH 02/13] Switch to pytest Signed-off-by: Julien Danjou --- tox.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index 7ef1822..a223283 100644 --- a/tox.ini +++ b/tox.ini @@ -4,8 +4,8 @@ envlist = py35,py36,pep8 [testenv] usedevelop = True deps = .[test] - nose -commands = nosetests + pytest +commands = pytest {posargs} [testenv:pep8] basepython = python3 From edecdb3587b9893d31969874bf3a6899a67d2d99 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 7 May 2019 14:25:11 +0200 Subject: [PATCH 03/13] Add support for Python 3.7, switch to CircleCI --- .circleci/config.yml | 50 ++++++++++++++++++++++++++++++++++++++++++++ .mergify.yml | 23 ++++++++++++++++++-- .travis.yml | 21 ------------------- setup.cfg | 1 + tox.ini | 7 ++----- 5 files changed, 74 insertions(+), 28 deletions(-) create mode 100644 .circleci/config.yml delete mode 100644 .travis.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..a9a1c1d --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,50 @@ +version: 2 + +jobs: + pep8: + docker: + - image: circleci/python:3.7 + steps: + - checkout + - run: + command: | + sudo pip install tox + tox -e pep8 + py35: + docker: + - image: circleci/python:3.5 + steps: + - checkout + - run: + command: | + sudo pip install tox + tox -e py35 + py36: + docker: + - image: circleci/python:3.6 + steps: + - checkout + - run: + command: | + sudo pip install tox + tox -e py36 + py37: + docker: + - image: circleci/python:3.7 + steps: + - checkout + - run: + command: | + sudo pip install tox + tox -e py37 + + +workflows: + version: 2 + + test: + jobs: + - pep8 + - py35 + - py36 + - py37 diff --git a/.mergify.yml b/.mergify.yml index dc06463..c7972dc 100644 --- a/.mergify.yml +++ b/.mergify.yml @@ -2,12 +2,31 @@ pull_request_rules: - name: automatic merge conditions: - base=master - - status-success=continuous-integration/travis-ci/pr + - "status-success=ci/circleci: pep8" + - "status-success=ci/circleci: py35" + - "status-success=ci/circleci: py36" + - "status-success=ci/circleci: py37" - "#approved-reviews-by>=1" - label!=work-in-progress actions: merge: - strict: "smart" + strict: true + - name: dismiss reviews + conditions: [] + actions: + dismiss_reviews: {} + - name: automatic merge no review + conditions: + - base=master + - "status-success=ci/circleci: pep8" + - "status-success=ci/circleci: py35" + - "status-success=ci/circleci: py36" + - "status-success=ci/circleci: py37" + - label=no-review-needed + - label!=work-in-progress + actions: + merge: + strict: true - name: dismiss reviews conditions: [] actions: diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 17e904f..0000000 --- a/.travis.yml +++ /dev/null @@ -1,21 +0,0 @@ -language: python -cache: - - pip -python: - - 3.5 - - 3.6 -before_install: - - pip install -U pip -install: - # The install requirements in travis virtualenv that will be cached - - pip install tox-travis .[test] -script: tox - -deploy: - provider: pypi - user: jd - password: - secure: lmW4Tgo5HZYh0Y01SEVJKQvbZlqUDME6T0hzNnQYUgasreWXO2v7+ZewIywQBgJD9LfEEIToyKOyYPlYM3m+vU/QF19IlfmMZphe2gNLDoqMr4Wn3Yxzv0pwgkRHe4coT1qaCXg31Dqb4Ab5pRAIu2gi5tGFBEqkgkxTTVkPfoFhv+TXar6qNbn/b/EXRsVgFnxo3MLn4q/aHMFsUds579P37wiaVnBmR4J3SHF1hbERmnTgtnv5MXhdb7P8fcXxfyeNPkLAmguh5KAaf98EwpuC+I6/ZDG/EueeBBHOdlq7JfXmskqPgksagAMAsH/8lDhuZHn3cb0FyF86a5d3YdJbFH0prOTDRXWa/Z96JHhklGXnLsJg2HTHrjabtn5DpZkAVUCJn8Ctor/8pDG3JAaC8HPLd1INoPpSGj0/RfMOyIUt6tRfDH7KjB0r6ZOjjwbWY9/SViABPFnyoT3PZRhSGwilJORQViANeJkJoMkmJYsi/U+wFvqcCb/kSsGbn4lJk0WkdWXvdVIrKX3ZYDgZ4vy6kEtHohLH9ZnlEDRWht+UqgRhDys6qtQOtY/ncK7miMhFIolBplAFU2vSfmGD8nXkkVCPugXJveSvHR83idNKmRoGwK2rqLb8LPinXwxRjs1Iqnfsh2QSomUinoCXdECV7p9XxDRFY2feOO8= - on: - tags: true - distributions: "sdist bdist_wheel" diff --git a/setup.cfg b/setup.cfg index 7376f7e..7a18745 100644 --- a/setup.cfg +++ b/setup.cfg @@ -13,6 +13,7 @@ classifier = Programming Language :: Python :: 3 Programming Language :: Python :: 3.5 Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 [files] packages = diff --git a/tox.ini b/tox.ini index a223283..6f48a2e 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py35,py36,pep8 +envlist = py35,py36,py37,pep8 [testenv] usedevelop = True @@ -22,7 +22,4 @@ commands = flake8 exclude = .tox,.eggs show-source = true ignore = D100,D101,D102,D103,D104,G200,G201,W504 -enable-extensions=G - -[travis] -python = 3.6: py36, pep8 +enable-extensions=G \ No newline at end of file From 9e1807535aedf64053d4bf37181f1c39f3203aa0 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 7 May 2019 16:22:32 +0200 Subject: [PATCH 04/13] Cleanup CONTRIBUTING --- CONTRIBUTING.md | 142 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 99 insertions(+), 43 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8df13da..bcb5d07 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,15 +3,15 @@ First off, thanks for taking the time to contribute! The following as a set of guidelines for contributing to git-pull-request. -These are mostly guidelines, not rules. Use your best judgment, and fell -free to propose changes to this document in a pull request. +These are mostly guidelines, not rules. Use your best judgment, and fell free +to propose changes to this document in a pull request. ## Code of Conduct -This project and everyone participating in it is governed -by the [git-pull-request Code of Conduct](CODE_OF_CONDUCT.md). -By participating, you are expected to uphold this code. -Please report unacceptable behavior to [julien@danjou.info](mailto:julien@danjou.info). +This project and everyone participating in it is governed by the +[git-pull-request Code of Conduct](CODE_OF_CONDUCT.md). By participating, you +are expected to uphold this code. Please report unacceptable behavior to +[jd@mergify.io](mailto:jd@mergify.io). ## How Can I Contribute? @@ -21,90 +21,146 @@ This section guides you through submitting a bug report for git-pull-request. Following these guidelines helps maintainers and the community understand your report, reproduce the behavior, and find related reports. -Before creating bug reports, please perform a -[cursory search](https://github.com/jd/git-pull-request/issues?q=is%3Aissue%20is%3Aopen%20) -to see if the problem has already been reported. -If it has and the issue is still open, add a comment to -the existing issue instead of opening a new one. -When you are creating a bug report, please [include as many details as possbile](#how-do-i-submit-a-good-bug-report). +Before creating bug reports, please perform a [cursory +search](https://github.com/Mergifyio/git-pull-request/issues?q=is%3Aissue%20is%3Aopen%20) +to see if the problem has already been reported. If it has and the issue is +still open, add a comment to the existing issue instead of opening a new one. +When you are creating a bug report, please [include as many details as +possbile](#how-do-i-submit-a-good-bug-report). -> **Note:** If you find a **Closed** issue that seems like it is the same thing that you're experiencing, open a new issue and include a link to the original issue in the body of your new one. +> **Note:** If you find a **Closed** issue that seems like it is the same thing +> that you're experiencing, open a new issue and include a link to the original +> issue in the body of your new one. #### How Do I Submit A (Good) Bug Report? -Bugs are tracked as [GitHub issues](https://guides.github.com/features/issues/). +Bugs are tracked as [GitHub +issues](https://guides.github.com/features/issues/). -Explain the problem and include additional details to help maintainers reproduce the problem: +Explain the problem and include additional details to help maintainers +reproduce the problem: * **Use a clear and descriptive title** for the issue to identify the problem. -* **Describe the exact steps which reproduce the problem** in as many details as possible. For example, start by explaining how you use the git-pull-request command line, e.g. which command exactly you used in the terminal. When listing steps, **don't just say what you did, but explain how you did it**. -* **Provide specific examples to demonstrate the steps**. Include links to files or GitHub projects, or copy/pasteable snippets, which you use in those examples. If you're providing snippets in the issue, use [Markdown code blocks](https://help.github.com/articles/markdown-basics/#multiple-lines). -* **Describe the behavior you observed after following the steps** and point out what exactly is the problem with that behavior. + +* **Describe the exact steps which reproduce the problem** in as many details + as possible. For example, start by explaining how you use the + git-pull-request command line, e.g. which command exactly you used in the + terminal. When listing steps, **don't just say what you did, but explain how + you did it**. + +* **Provide specific examples to demonstrate the steps**. Include links to + files or GitHub projects, or copy/pasteable snippets, which you use in those + examples. If you're providing snippets in the issue, use [Markdown code + blocks](https://help.github.com/articles/markdown-basics/#multiple-lines). + +* **Describe the behavior you observed after following the steps** and point + out what exactly is the problem with that behavior. + * **Explain which behavior you expected to see instead and why.** Provide more context by answering these questions: -* **Did the problem start happening recently** (e.g. after updating to a new version of git-pull-request) or was this always a problem? -* If the problem started happening recently, **can you reproduce the problem in an older version of git-pull-request?** What's the most recent version in which the problem doesn't happen? You can install older versions of git-pull-request from [the pypi repository](https://pypi.python.org/pypi/git-pull-request/). -* **Can you reliably reproduce the issue?** If not, provide details about how often the problem happens and under which conditions it normally happens. +* **Did the problem start happening recently** (e.g. after updating to a new + version of git-pull-request) or was this always a problem? + +* If the problem started happening recently, **can you reproduce the problem in + an older version of git-pull-request?** What's the most recent version in + which the problem doesn't happen? You can install older versions of + git-pull-request from [the pypi + repository](https://pypi.python.org/pypi/git-pull-request/). + +* **Can you reliably reproduce the issue?** If not, provide details about how + often the problem happens and under which conditions it normally happens. + Include details about your configuration and environment: -* **Which version of git-pull-request are you using?** You can get the exact version by running `pip freeze | grep "git-pull-request"` in your terminal. +* **Which version of git-pull-request are you using?** You can get the exact + version by running `pip freeze | grep "git-pull-request"` in your terminal. + * **What's the name and version of the OS you're using**? + * **What's the version of python you're using**? ### Suggesting Enhancements -This section guides you through submitting an enhancement suggestion for git-pull-request, including completely new features and minor improvements to existing functionality. Following these guidelines helps maintainers and the community understand your suggestion and find related suggestions. +This section guides you through submitting an enhancement suggestion for +git-pull-request, including completely new features and minor improvements to +existing functionality. Following these guidelines helps maintainers and the +community understand your suggestion and find related suggestions. -When you are creating an enhancement suggestion, please [include as many details as possible](#how-do-i-submit-a-good-enhancement-suggestion) and including the steps that you imagine you would take if the feature you're requesting existed. +When you are creating an enhancement suggestion, please [include as many +details as possible](#how-do-i-submit-a-good-enhancement-suggestion) and +including the steps that you imagine you would take if the feature you're +requesting existed. #### How Do I Submit A (Good) Enhancement Suggestion? -Enhancement suggestions are tracked as [GitHub issues](https://guides.github.com/features/issues/). +Enhancement suggestions are tracked as [GitHub +issues](https://guides.github.com/features/issues/). Provide the following information: -* **Use a clear and descriptive title** for the issue to identify the suggestion. -* **Provide a step-by-step description of the suggested enhancement** in as many details as possible. -* **Provide specific examples to demonstrate the steps**. Include copy/pasteable snippets which you use in those examples, as [Markdown code blocks](https://help.github.com/articles/markdown-basics/#multiple-lines). -* **Describe the current behavior** and **explain which behavior you expected to see instead** and why. -* **Include screenshots and animated GIFs** which help you demonstrate the steps or point out the part of git-pull-request which the suggestion is related to. You can use [this tool](https://www.cockos.com/licecap/) to record GIFs on macOS and Windows, and [this tool](https://github.com/colinkeenan/silentcast) or [this tool](https://github.com/GNOME/byzanz) on Linux. -* **Explain why this enhancement would be useful** to most git-pull-request users. +* **Use a clear and descriptive title** for the issue to identify the + suggestion. + +* **Provide a step-by-step description of the suggested enhancement** in as + many details as possible. + +* **Provide specific examples to demonstrate the steps**. Include + copy/pasteable snippets which you use in those examples, as [Markdown code + blocks](https://help.github.com/articles/markdown-basics/#multiple-lines). + +* **Describe the current behavior** and **explain which behavior you expected + to see instead** and why. + +* **Include screenshots and animated GIFs** which help you demonstrate the + steps or point out the part of git-pull-request which the suggestion is + related to. You can use [this tool](https://www.cockos.com/licecap/) to + record GIFs on macOS and Windows, and [this + tool](https://github.com/colinkeenan/silentcast) or [this + tool](https://github.com/GNOME/byzanz) on Linux. + +* **Explain why this enhancement would be useful** to most git-pull-request + users. + * **List some other tools or applications where this enhancement exists.** -* **Specify which version of git-pull-request you're using.** You can get the exact version by running `pip freeze| grep "git-pull-request"` in your terminal. + +* **Specify which version of git-pull-request you're using.** You can get the + exact version by running `pip freeze| grep "git-pull-request"` in your + terminal. + * **Specify the name and version of the OS you're using.** + * **Specify the version of python you're using** ## Code Contribution ### Hacking on git-pull-request -If you're hitting a bug in git-pull-request or just want to experiment with adding a feature, follow these steps. +If you're hitting a bug in git-pull-request or just want to experiment with +adding a feature, follow these steps. #### Prerequisites -- [venv](https://docs.python.org/3/library/venv.html) or consider [pipenv](https://github.com/kennethreitz/pipenv) -- [pbr](https://docs.openstack.org/pbr/latest/) -- python3.5+ +- Python >= 3.5 #### Cloning ``` command-line -$ git clone https://github.com/jd/git-pull-request +$ git clone https://github.com/Mergifyio/git-pull-request ``` #### Setup your environment -From there, you can navigate into the directory where you've cloned the git-pull-request source code, create a virtual environment and install all the required dependencies: +From there, you can navigate into the directory where you've cloned the +git-pull-request source code, create a virtual environment and install all the +required dependencies: ``` command-line $ cd git-pull-request -$ venv . -$ pip install -r requirements.txt -$ python setup.py develop +$ pip install -e . ``` #### Make your changes @@ -114,7 +170,7 @@ $ git checkout -b somefeature $ git commit -am 'I did some changes' $ git pull-request -Forked repository: https://github.com/jd/git-pull-request +Forked repository: https://github.com/Mergifyio/git-pull-request Force-pushing branch `somefeature' to remote `github' Counting objects: 5, done. Delta compression using up to 4 threads. @@ -122,7 +178,7 @@ Compressing objects: 100% (4/4), done. Writing objects: 100% (5/5), 562 bytes | 0 bytes/s, done. Total 5 (delta 3), reused 0 (delta 0) remote: Resolving deltas: 100% (3/3), completed with 3 local objects. -To https://github.com/jd/git-pull-request.git +To https://github.com/Mergifyio/git-pull-request.git + 73a733f7...1be2bf29 somefeature -> somefeature (forced update) Pull-request created: https://github.com/git-pull-requestxyz/git-pull-request/pull/33 ``` From fc27c729519f1c12c10e9a4512272a2a4daab43d Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 7 May 2019 16:26:31 +0200 Subject: [PATCH 05/13] Switch from pbr to setuptools_scm --- requirements.txt | 2 -- setup.cfg | 20 ++++++++++++-------- setup.py | 5 +++-- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/requirements.txt b/requirements.txt index 68dc01e..e69de29 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +0,0 @@ -pygithub -daiquiri diff --git a/setup.cfg b/setup.cfg index 7a18745..fe6e5e2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,11 +1,12 @@ [metadata] name = git-pull-request -home-page = https://github.com/jd/git-pull-request -summary = Command line tool to send GitHub pull-request +home-page = https://github.com/Mergifyio/git-pull-request +summary = Command line tool to send GitHub pull requests description-file = README.rst author = Julien Danjou -author-email = julien@danjou.info +author-email = jd@mergify.io classifier = + Intended Audience :: Developers Intended Audience :: Information Technology License :: OSI Approved :: Apache Software License Operating System :: POSIX @@ -15,15 +16,18 @@ classifier = Programming Language :: Python :: 3.6 Programming Language :: Python :: 3.7 -[files] -packages = - git_pull_request +[options] +packages = find: +install_requires = + pygithub + daiquiri -[extras] + +[options.extras_require] test = fixtures -[entry_points] +[options.entry_points] console_scripts = git-pull-request = git_pull_request:main diff --git a/setup.py b/setup.py index ed58d0f..3f030ec 100755 --- a/setup.py +++ b/setup.py @@ -2,5 +2,6 @@ import setuptools setuptools.setup( - setup_requires=['pbr'], - pbr=True) + setup_requires=['setuptools_scm'], + use_scm_version=True, +) From 978a5b72ec98b73a6d4ce3eadf91910e369cf657 Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Wed, 8 May 2019 01:54:01 +0000 Subject: [PATCH 06/13] Report on success to git credential This tells git credential that the password worked and that it can be re-used. --- git_pull_request/__init__.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/git_pull_request/__init__.py b/git_pull_request/__init__.py index e44b61a..c716ec6 100644 --- a/git_pull_request/__init__.py +++ b/git_pull_request/__init__.py @@ -74,6 +74,20 @@ def get_login_password(protocol="https", host="github.com"): return username, password +def approve_login_password(user, password, + host="github.com", protocol="https"): + """Tell git to approve the credential.""" + subp = subprocess.Popen(["git", "credential", "approve"], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE) + request = "protocol={}\nhost={}\nusername={}\npassword={}\n".format( + protocol, host, user, password).encode() + subp.communicate(input=request) + ret = subp.wait() + if ret != 0: + LOG.error("git credential returned exited with status %d", ret) + + def git_remote_matching_url(url): remotes = _run_shell_command(["git", "remote", "-v"], output=True).split('\n') @@ -286,6 +300,7 @@ def git_pull_request(target_remote=None, target_branch=None, comment, force_editor, tag_previous_revision, dont_fork) + approve_login_password(host=hostname, user=user, password=password) def download_pull_request(g, repo, target_remote, pull_number): From 1319578f3e55133083aab235727deb108a3e420f Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Wed, 8 May 2019 02:03:34 +0000 Subject: [PATCH 07/13] Add git-scm.com link for git credential The official git documentation gives more informations about credential. --- README.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.rst b/README.rst index 182a891..f392ca7 100644 --- a/README.rst +++ b/README.rst @@ -53,6 +53,9 @@ Caching Credentials GitHub has a good documentation about using `git credential `_. +The full documentation is available on the `git-scm.com website +`_. + Creating Branches ----------------- From 56df8517b38351d12389d1f9f6b488802e13fa49 Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Wed, 8 May 2019 00:56:58 +0000 Subject: [PATCH 08/13] Name the remote to push with the host type This changes the default remote name to match the host type so that pagure repository gets a "pagure" remote instead of a confusing "github" one. --- git_pull_request/__init__.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/git_pull_request/__init__.py b/git_pull_request/__init__.py index e44b61a..3afeb16 100644 --- a/git_pull_request/__init__.py +++ b/git_pull_request/__init__.py @@ -267,11 +267,11 @@ def git_pull_request(target_remote=None, target_branch=None, LOG.debug("Found %s user: `%s' password: ", hostname, user) - kwargs = {} if hosttype == "pagure": g = pagure.Client(hostname, user, password, reponame_to_fork) repo = g.get_repo(reponame_to_fork) else: + kwargs = {} if hostname != "github.com": kwargs['base_url'] = "https://" + hostname + "/api/v3" LOG.debug("Using API base url `%s'", kwargs['base_url']) @@ -281,7 +281,7 @@ def git_pull_request(target_remote=None, target_branch=None, if download is not None: download_pull_request(g, repo, target_remote, download) else: - fork_and_push_pull_request(g, repo, rebase, target_remote, + fork_and_push_pull_request(g, hosttype, repo, rebase, target_remote, target_branch, branch, user, title, message, comment, force_editor, tag_previous_revision, @@ -367,9 +367,9 @@ def preserve_older_revision(branch, remote_to_push): _run_shell_command(["git", "tag", "-d", tag]) -def fork_and_push_pull_request(g, repo_to_fork, rebase, target_remote, - target_branch, branch, user, title, message, - comment, +def fork_and_push_pull_request(g, hosttype, repo_to_fork, rebase, + target_remote, target_branch, branch, user, + title, message, comment, force_editor, tag_previous_revision, dont_fork): g_user = g.get_user() @@ -387,7 +387,7 @@ def fork_and_push_pull_request(g, repo_to_fork, rebase, target_remote, LOG.debug("Found forked repository already in remote as `%s'", remote_to_push) else: - remote_to_push = "github" + remote_to_push = hosttype _run_shell_command( ["git", "remote", "add", remote_to_push, repo_forked.clone_url]) From c3b6d1a4a665431c39ecf46c00451d17468b9f60 Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Wed, 8 May 2019 01:03:46 +0000 Subject: [PATCH 09/13] Discover the clone url of pagure repository This fixes git pull-request with pagure hosts that use the real user name instead of "git". --- git_pull_request/pagure.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/git_pull_request/pagure.py b/git_pull_request/pagure.py index 08747b9..ce6d47d 100644 --- a/git_pull_request/pagure.py +++ b/git_pull_request/pagure.py @@ -91,12 +91,15 @@ def enable_pull_request(self, project): options = {"pull_requests": True} self.post("%s/options/update" % project, options) - def create_fork(self, _): - class ForkedRepo: - clone_url = "ssh://git@%s/forks/%s/%s.git" % ( - self.host, self.user, self.reponame_to_fork) - html_url = "https://%s/%s" % (self.host, self.fork_path) + def get_repo_urls(self, reponame): + urls = self.get("{}/git/urls".format(reponame))["urls"] + if "ssh" not in urls: + raise RuntimeError("%s: ssh url is missing" % reponame) + return type('ForkedRepo', (object,), dict( + clone_url=urls["ssh"].format(username=self.user), + html_url=urls["git"])) + def create_fork(self, _): LOG.debug("check if the fork already exists") if not self.get(self.fork_path, error_ok=True): LOG.info("requesting a fork creation") @@ -109,7 +112,7 @@ class ForkedRepo: self.post("fork", {"repo": repo, "namespace": namespace, "wait": True}) self.enable_pull_request(self.fork_path) - return ForkedRepo + return self.get_repo_urls(self.fork_path) def get_pulls(self, base, head): class Pull: From 2ab4ad4565db8ec28be24910ab875418392f3d31 Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Wed, 8 May 2019 01:45:57 +0000 Subject: [PATCH 10/13] Add pagure token documentation This adds back the instruction to get a valid token for the pagure API. --- README.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.rst b/README.rst index f392ca7..11fdaca 100644 --- a/README.rst +++ b/README.rst @@ -56,6 +56,13 @@ GitHub has a good documentation about using `git credential The full documentation is available on the `git-scm.com website `_. +Pagure Token +------------ + +Pagure uses API key, you need to create one by visiting `your settings +`_ +and requesting the `Fork a project` and `Modify an existing project` ACL. + Creating Branches ----------------- From a0f49fc2e859d3514d1c869d6db530bf518d67a2 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 10 May 2019 11:22:49 +0200 Subject: [PATCH 11/13] Fix setup.cfg field names Signed-off-by: Julien Danjou --- setup.cfg | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.cfg b/setup.cfg index fe6e5e2..98b7420 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,8 +1,8 @@ [metadata] name = git-pull-request -home-page = https://github.com/Mergifyio/git-pull-request -summary = Command line tool to send GitHub pull requests -description-file = README.rst +url = https://github.com/Mergifyio/git-pull-request +description = Command line tool to send GitHub pull requests +long_description = file: README.rst author = Julien Danjou author-email = jd@mergify.io classifier = From 751a14200586bb5676a19dbfc6e6366dfad60798 Mon Sep 17 00:00:00 2001 From: Mehdi Abaakouk Date: Tue, 4 Jun 2019 09:21:58 +0200 Subject: [PATCH 12/13] Allow to only setup the fork repo --- git_pull_request/__init__.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/git_pull_request/__init__.py b/git_pull_request/__init__.py index ce3363c..b238fb9 100644 --- a/git_pull_request/__init__.py +++ b/git_pull_request/__init__.py @@ -228,7 +228,8 @@ def git_pull_request(target_remote=None, target_branch=None, force_editor=False, download=None, tag_previous_revision=False, - dont_fork=True): + dont_fork=True, + setup_only=False): branch = git_get_branch_name() if not branch: LOG.critical("Unable to find current branch") @@ -299,7 +300,7 @@ def git_pull_request(target_remote=None, target_branch=None, target_branch, branch, user, title, message, comment, force_editor, tag_previous_revision, - dont_fork) + dont_fork, setup_only) approve_login_password(host=hostname, user=user, password=password) @@ -385,7 +386,8 @@ def preserve_older_revision(branch, remote_to_push): def fork_and_push_pull_request(g, hosttype, repo_to_fork, rebase, target_remote, target_branch, branch, user, title, message, comment, - force_editor, tag_previous_revision, dont_fork): + force_editor, tag_previous_revision, dont_fork, + setup_only): g_user = g.get_user() @@ -409,6 +411,11 @@ def fork_and_push_pull_request(g, hosttype, repo_to_fork, rebase, LOG.info("Added forked repository as remote `%s'", remote_to_push) head = "{}:{}".format(user, branch) + if setup_only: + LOG.info("Fetch existing branches of remote `%s`", remote_to_push) + _run_shell_command(["git", "fetch", remote_to_push]) + return + if rebase: _run_shell_command(["git", "remote", "update", target_remote]) @@ -554,6 +561,12 @@ def main(): default=False, help="Don't fork to create the pull-request" ) + parser.add_argument( + "--setup-only", + action="store_true", + default=False, + help="Just setup the fork repo" + ) args = parser.parse_args() @@ -577,7 +590,8 @@ def main(): force_editor=args.force_editor, download=args.download, tag_previous_revision=args.tag_previous_revision, - dont_fork=args.no_fork + dont_fork=args.no_fork, + setup_only=args.setup_only ) except Exception: LOG.error("Unable to send pull request", exc_info=True) From a53d2dbd74a9b7831bc768fdcf7a8e754758334c Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Tue, 4 Jun 2019 08:57:16 +0000 Subject: [PATCH 13/13] get_commit_body: prevent exception when branch name is a filename This changes adds a filename separator to the git show command to prevent an exception from happening when the branch name is a filename: fatal: ambiguous argument 'name': both revision and filename --- git_pull_request/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git_pull_request/__init__.py b/git_pull_request/__init__.py index b238fb9..340bb93 100644 --- a/git_pull_request/__init__.py +++ b/git_pull_request/__init__.py @@ -187,7 +187,7 @@ def parse_pr_message(message): def git_get_commit_body(commit): return _run_shell_command( - ["git", "show", "-q", "--format=%b", commit], + ["git", "show", "-q", "--format=%b", commit, '--'], output=True)