Skip to content

Commit

Permalink
Merge pull request #110 from pelson/conda_linting
Browse files Browse the repository at this point in the history
Added automatic conda-linting to all repos.
  • Loading branch information
pelson committed Apr 2, 2016
2 parents 3975c6d + 9b01f82 commit 1fada6a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 14 deletions.
49 changes: 43 additions & 6 deletions conda_smithy/ci_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import requests
import time

from conda_smithy import vendored
from conda_smithy.vendored import travis_encrypt as travis
import ruamel.yaml

from .vendored import travis_encrypt as travis
from . import github


# https://circleci.com/docs/api#add-environment-variable

# curl -X POST --header "Content-Type: application/json" -d '{"name":"foo", "value":"bar"}'
Expand Down Expand Up @@ -135,9 +138,7 @@ def add_project_to_travis(user, project):
}
endpoint = 'https://api.travis-ci.org'
url = '{}/auth/github'.format(endpoint)
with open(os.path.expanduser('~/.conda-smithy/github.token'), 'r') as fh:
github_token = fh.read().strip()
data = {"github_token": github_token}
data = {"github_token": github.gh_token()}
response = requests.post(url, json=data, headers=headers)
if response.status_code != 201:
response.raise_for_status()
Expand Down Expand Up @@ -212,17 +213,53 @@ def travis_token_update_conda_forge_config(feedstock_directory, user, project):
def _encrypt_binstar_token(slug, item):
return travis.encrypt(slug, item.encode()).decode('utf-8')


def add_conda_linting(user, repo):
if user != 'conda-forge':
print('Unable to register {}/{} for conda-linting at this time as only '
'conda-forge repos are supported.'.format(user, repo))

headers = {'Authorization': 'token {}'.format(github.gh_token())}
url = 'https://api.github.com/repos/{}/{}/hooks'.format(user, repo)

# Get the current hooks to determine if anything needs doing.
response = requests.get(url, headers=headers)
registered = response.json()
hook_by_url = {hook['config'].get('url'): hook for hook in registered
if 'url' in hook['config']}

hook_url = "http://conda-forge.herokuapp.com/conda-linting/hook"

payload = {
"name": "web",
"active": True,
"events": [
"pull_request"
],
"config": {
"url": hook_url,
"content_type": "json"
}
}

if hook_url not in hook_by_url:
response = requests.post(url, json=payload, headers=headers)
if response.status_code != 200:
response.raise_for_status()


if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("user")
parser.add_argument("project")
args = parser.parse_args(['pelson', 'udunits-delme-feedstock'])
args = parser.parse_args(['conda-forge', 'conda-smithy-feedstock'])

# add_project_to_circle(args.user, args.project)
# add_project_to_appveyor(args.user, args.project)
# add_project_to_travis(args.user, args.project)
# appveyor_encrypt_binstar_token('../udunits-delme-feedstock', args.user, args.project)
# appveyor_configure('conda-forge', 'glpk-feedstock')
# travis_token_update_conda_forge_config('../udunits-delme-feedstock', args.user, args.project)
add_conda_linting(args.user, 'matplotlib-feedstock')
print('Done')
1 change: 1 addition & 0 deletions conda_smithy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def __call__(self, args):
ci_register.add_project_to_appveyor(owner, repo)
ci_register.appveyor_encrypt_binstar_token(args.feedstock_directory, owner, repo)
ci_register.appveyor_configure(owner, repo)
ci_register.add_conda_linting(owner, repo)
print("\nCI services have been enabled enabled. You may wish to regnerate the feedstock.\n"
"Any changes will need commiting to the repo.")
except RuntimeError as e:
Expand Down
16 changes: 8 additions & 8 deletions conda_smithy/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@


def gh_token():
try:
with open(os.path.expanduser('~/.conda-smithy/github.token'), 'r') as fh:
token = fh.read().strip()
except IOError:
msg = ('No github token. Go to https://github.com/settings/tokens/new and generate\n'
'a token with repo access. Put it in ~/.conda-smithy/github.token')
raise RuntimeError(msg)
return token
try:
with open(os.path.expanduser('~/.conda-smithy/github.token'), 'r') as fh:
token = fh.read().strip()
except IOError:
msg = ('No github token. Go to https://github.com/settings/tokens/new and generate\n'
'a token with repo access. Put it in ~/.conda-smithy/github.token')
raise RuntimeError(msg)
return token


def create_github_repo(args):
Expand Down

0 comments on commit 1fada6a

Please sign in to comment.