mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Use requests instead of github package. Also output the PR incoming branch.
This commit is contained in:
parent
864ad4b3a2
commit
672e98cf0f
1 changed files with 29 additions and 29 deletions
|
@ -44,10 +44,10 @@ except ImportError:
|
|||
# Import 3rd-party libs
|
||||
import yaml
|
||||
try:
|
||||
import github
|
||||
HAS_GITHUB = True
|
||||
import requests
|
||||
HAS_REQUESTS = True
|
||||
except ImportError:
|
||||
HAS_GITHUB = False
|
||||
HAS_REQUESTS = False
|
||||
|
||||
SALT_GIT_URL = 'https://github.com/saltstack/salt.git'
|
||||
|
||||
|
@ -139,37 +139,37 @@ def echo_parseable_environment(options):
|
|||
# This is a Jenkins triggered Pull Request
|
||||
# We need some more data about the Pull Request available to the
|
||||
# environment
|
||||
if not HAS_GITHUB:
|
||||
print('# The script NEEDS the github python package installed')
|
||||
sys.stdout.write('\n'.join(output))
|
||||
sys.stdout.flush()
|
||||
return
|
||||
if HAS_REQUESTS is False:
|
||||
parser.error(
|
||||
'The python \'requests\' library needs to be installed'
|
||||
)
|
||||
|
||||
headers = {}
|
||||
url = 'https://api.github.com/repos/saltstack/salt/pulls/{0}'.format(values)
|
||||
|
||||
github_access_token_path = os.path.join(
|
||||
os.environ['JENKINS_HOME'], '.github_token'
|
||||
os.environ.get('JENKINS_HOME', os.path.expanduser('~')),
|
||||
'.github_token'
|
||||
)
|
||||
if not os.path.isfile(github_access_token_path):
|
||||
print(
|
||||
'# The github token file({0}) does not exit'.format(
|
||||
github_access_token_path
|
||||
if os.path.isfile(github_access_token_path):
|
||||
headers = {
|
||||
'Authorization': 'token {0}'.format(
|
||||
open(github_access_token_path).read().strip()
|
||||
)
|
||||
)
|
||||
sys.stdout.write('\n'.join(output))
|
||||
sys.stdout.flush()
|
||||
return
|
||||
}
|
||||
|
||||
GITHUB = github.Github(open(github_access_token_path).read().strip())
|
||||
REPO = GITHUB.get_repo('saltstack/salt')
|
||||
try:
|
||||
PR = REPO.get_pull(options.pull_request)
|
||||
output.extend([
|
||||
'SALT_PR_GIT_URL={0}'.format(PR.head.repo.clone_url),
|
||||
'SALT_PR_GIT_COMMIT={0}'.format(PR.head.sha)
|
||||
])
|
||||
options.test_git_url = PR.head.repo.clone_url
|
||||
options.test_git_commit = PR.head.sha
|
||||
except ValueError:
|
||||
print('# Failed to get the PR id from the environment')
|
||||
http_req = requests.get(url, headers=headers)
|
||||
if http_req.status_code != 200:
|
||||
parser.error(
|
||||
'Unable to get the pull request: {0[message]}'.format(http_req.json())
|
||||
)
|
||||
|
||||
pr_details = http_req.json()
|
||||
output.extend([
|
||||
'SALT_PR_GIT_URL={0}'.format(pr_details['head']['repo']['clone_url']),
|
||||
'SALT_PR_GIT_BRANCH={0}'.format(pr_details['head']['ref']),
|
||||
'SALT_PR_GIT_COMMIT={0}'.format(pr_details['head']['sha'])
|
||||
])
|
||||
|
||||
sys.stdout.write('\n\n{0}\n\n'.format('\n'.join(output)))
|
||||
sys.stdout.flush()
|
||||
|
|
Loading…
Add table
Reference in a new issue