Skip to content

Automatically create backport PR if oauth token is set #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Sep 1, 2017

Conversation

Mariatta
Copy link
Member

@Mariatta Mariatta commented Aug 27, 2017

  • Add gidgethub and requests as dependencies.

Closes #100

- Provide instructions on how to generate the personal access token, and how to set it as an environment variable.

- Add gidgethub and requests as dependencies.
@Mariatta
Copy link
Member Author

python/cpython#3224 was created via this method, using my own personal access token.

@Mariatta Mariatta requested a review from brettcannon August 27, 2017 22:35
@terryjreedy
Copy link
Member

I have read the readme, but it is not clear to me what 'create automatically' means -- what will happen, when and where -- and what a token on my machine has to do with it.

@Mariatta
Copy link
Member Author

Thanks @terryjreedy. The idea is instead of opening a web browser where we have to click the 'Create pull request button', cherry picker will create the PR. So no web browser will be opened at all.
cherry_picker will print out the URL of the newly created pull request.

The token is needed by GitHub API as a way to authenticate your GitHub account.

@terryjreedy
Copy link
Member

Thanks for explaining. Since I like to have the PR open in my browser, and clicking the button is an easy way to get that, I will probably pass.

@Mariatta
Copy link
Member Author

No prob :) It's backward compatible, so the previous way still works as is.

Potentially we can use this for the cherry-picking bot, where the backport will happen automatically after we merge the PR on master. (Issue #8)

Personal Access Token (optional)
--------------------------------

``cherry_picker`` can automatically create the PR, if the ``GH_AUTH`` token is set
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this considered safe and best practice for storing an auth token like this? I honestly don't know, which is why I'm asking. 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really know 😅
This is really so I can use it for the cherry picker bot later.
Maybe I should keep this as hidden and secret functionality, and not mention it at all in the readme?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, either don't document it or be clear that one should be careful about how that environment variable is stored.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I'm going with "not documenting it" since it's easier to do than coming up with warning messages 😅

@Mariatta
Copy link
Member Author

I didn't expect the Spanish Inquisition!

@@ -6,9 +6,13 @@
import subprocess
import webbrowser
import sys
import requests

from gidgethub.sansio import create_headers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not important, but you shifted from importing modules to importing objects with this import line.

else:
self.open_pr(self.get_pr_url(https://github.com/base_branch,%20head_branch))

def create_gh_pr(self, base_branch, head_branch, commit_message):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're already checking for the envvar above, would it make sense to make it a required argument and just pass it in explicitly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I made the token a required argument.

@@ -8,7 +8,7 @@
import sys
import requests

from gidgethub.sansio import create_headers
import gidgethub
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should either be import gidgethub.sansio or from gidgethub import sansio; the fact that the package has an import is undocumented.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed tofrom gidgethub import sansio

else:
self.open_pr(self.get_pr_url(https://github.com/base_branch,%20head_branch))

def create_gh_pr(self, base_branch, head_branch, commit_message):
request_headers = create_headers(self.username, oauth_token=os.getenv("GH_AUTH"))
def create_gh_pr(self, base_branch, head_branch, commit_message, gh_auth):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any worry the order of these arguments will be non-obvious? I.e. should any of them be keyword-only arguments?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, ok I made commit_message and gh_auth as keyword only arguments.

made commit_message and gh_auth keyword only args in create_gh_pr
@Mariatta Mariatta merged commit 13f89f7 into python:master Sep 1, 2017
@Mariatta Mariatta deleted the use-gidgethub branch September 1, 2017 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants