Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e30df76
advise pr labels in --review-pr
migueldiascosta Jan 27, 2020
0eb57e9
compare with actual PR labels
migueldiascosta Feb 18, 2020
0e5beaf
try to set missing labels
migueldiascosta Feb 19, 2020
1b990bb
remove unnecessary decorator and don't raise error if github user or …
migueldiascosta Mar 30, 2020
97e6644
flesh out code to determine labels into separate function
migueldiascosta Apr 8, 2020
24207e8
revert posting labels in --review-pr
migueldiascosta Apr 8, 2020
430cbe5
also consider easyblocks in new det_labels function
migueldiascosta Apr 8, 2020
6c3a435
Merge branch 'develop' into review_pr_labels
migueldiascosta Apr 8, 2020
7ab4be8
add missing import
migueldiascosta Apr 8, 2020
f537040
Merge branch 'review_pr_labels' of github.com:migueldiascosta/easybui…
migueldiascosta Apr 8, 2020
4138715
move det_labels to github.py
migueldiascosta Apr 8, 2020
947fb72
fix wrong indentation
migueldiascosta Apr 9, 2020
056dd34
get correct pr_target_repo for review_pr and exit if it is not easyco…
migueldiascosta Apr 9, 2020
e23f00c
also test for label advice in test_review_pr
migueldiascosta Apr 9, 2020
ace7b59
add test for det_labels
migueldiascosta Apr 9, 2020
ed887fe
appease the hound
migueldiascosta Apr 9, 2020
ca66c6d
Merge branch 'develop' into review_pr_labels
migueldiascosta Apr 9, 2020
3d32296
cleanup code
migueldiascosta Apr 11, 2020
88c6d14
ignore PR labels when testing --review-pr label suggestions
migueldiascosta Apr 12, 2020
ef3979e
add support for --add-pr-labels
migueldiascosta Apr 12, 2020
229c391
Merge branch 'develop' of github.com:easybuilders/easybuild-framework…
migueldiascosta Apr 12, 2020
5155d2f
Merge branch 'develop' into review_pr_labels
boegel May 19, 2020
42f59bb
sync with develop
migueldiascosta Sep 14, 2020
043e65c
add test for add_pr_labels
migueldiascosta Sep 14, 2020
8b761d0
fix conflict
migueldiascosta Sep 14, 2020
31bd938
fix ambiguous variable name
migueldiascosta Sep 14, 2020
d9f272a
fix test for add_pr_labels
migueldiascosta Sep 16, 2020
3d4fc64
add new sandboxed easyblocks to test_list_easyblocks
migueldiascosta Sep 16, 2020
c89e672
Merge branch 'develop' into review_pr_labels
migueldiascosta Oct 14, 2020
ca1d9c3
Merge branch 'develop' into review_pr_labels
migueldiascosta Dec 1, 2020
83662ac
Merge branch 'develop' into review_pr_labels
migueldiascosta Dec 1, 2020
5c3a069
Merge branch 'develop' into review_pr_labels
boegel Feb 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions easybuild/framework/easyconfig/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@
from easybuild.base import fancylogger
from easybuild.framework.easyconfig import EASYCONFIGS_PKG_SUBDIR
from easybuild.framework.easyconfig.easyconfig import EASYCONFIGS_ARCHIVE_DIR, ActiveMNS, EasyConfig
from easybuild.framework.easyconfig.easyconfig import create_paths, get_easyblock_class, process_easyconfig
from easybuild.framework.easyconfig.easyconfig import create_paths, det_file_info, get_easyblock_class
from easybuild.framework.easyconfig.easyconfig import process_easyconfig
from easybuild.framework.easyconfig.format.yeb import quote_yaml_special_chars
from easybuild.framework.easyconfig.style import cmdline_easyconfigs_style_check
from easybuild.tools.build_log import EasyBuildError, print_msg, print_warning
from easybuild.tools.config import build_option
from easybuild.tools.environment import restore_env
from easybuild.tools.filetools import find_easyconfigs, is_patch_file, read_file, resolve_path, which, write_file
from easybuild.tools.github import fetch_easyconfigs_from_pr, download_repo
from easybuild.tools.github import download_repo, fetch_easyconfigs_from_pr, fetch_pr_data, post_pr_labels
from easybuild.tools.multidiff import multidiff
from easybuild.tools.py2vs3 import OrderedDict
from easybuild.tools.toolchain.toolchain import is_system_toolchain
Expand Down Expand Up @@ -538,6 +539,28 @@ def review_pr(paths=None, pr=None, colored=True, branch='develop'):
else:
lines.extend(['', "(no related easyconfigs found for %s)\n" % os.path.basename(ec['spec'])])

labels = []
file_info = det_file_info(pr_files, download_repo_path)
if any(file_info['new_folder']):
labels.append('new')
if any(file_info['new_file_in_existing_folder']):
labels.append('update')

github_account = build_option('pr_target_account')
github_repo = build_option('pr_target_repo')
github_user = build_option('github_user')
pr_data, _ = fetch_pr_data(pr, github_account, github_repo, github_user)
pr_labels = [label['name'] for label in pr_data['labels']]

missing_labels = []
for label in labels:
if label not in pr_labels:
missing_labels.append(label)

if missing_labels:
if not post_pr_labels(pr, labels):
lines.extend(['', "This PR should be labeled %s" % ', '.join(missing_labels)])

return '\n'.join(lines)


Expand Down
46 changes: 38 additions & 8 deletions easybuild/tools/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,42 @@ def merge_url(gh):
print_warning("Review indicates this PR should not be merged (use -f/--force to do so anyway)")


def post_pr_labels(pr, labels):
"""
Update PR labels
"""
pr_target_account = build_option('pr_target_account')
pr_target_repo = build_option('pr_target_repo')

# fetch GitHub token if available
github_user = build_option('github_user')
if github_user is None:
_log.info("GitHub user not specified, not adding labels to PR# %s" % pr)
return False

github_token = fetch_github_token(github_user)
if github_token is None:
_log.info("GitHub token for user '%s' not found, not adding labels to PR# %s" % (github_user, pr))
return False

dry_run = build_option('dry_run') or build_option('extended_dry_run')

if not dry_run:
g = RestClient(GITHUB_API_URL, username=github_user, token=github_token)

pr_url = g.repos[pr_target_account][pr_target_repo].issues[pr]
try:
status, data = pr_url.labels.post(body=labels)
if status == HTTP_STATUS_OK:
print_msg("Added labels %s to PR#%s" % (', '.join(labels), pr), log=_log, prefix=False)
return True
except HTTPError as err:
_log.info("Failed to add labels to PR# %s: %s." % (pr, err))
return False
else:
return True


@only_if_module_is_available('git', pkgname='GitPython')
def new_branch_github(paths, ecs, commit_msg=None):
"""
Expand Down Expand Up @@ -1479,15 +1515,9 @@ def new_pr_from_branch(branch_name, title=None, descr=None, pr_metadata=None):
print_msg("Opened pull request: %s" % data['html_url'], log=_log, prefix=False)

if labels:
# post labels
pr = data['html_url'].split('/')[-1]
pr_url = g.repos[pr_target_account][pr_target_repo].issues[pr]
try:
status, data = pr_url.labels.post(body=labels)
if status == HTTP_STATUS_OK:
print_msg("Added labels %s to PR#%s" % (', '.join(labels), pr), log=_log, prefix=False)
except HTTPError as err:
_log.info("Failed to add labels to PR# %s: %s." % (pr, err))
if not post_pr_labels(pr, labels):
print_msg("This PR should be labeled %s" % ', '.join(labels), log=_log, prefix=False)


def new_pr(paths, ecs, title=None, descr=None, commit_msg=None):
Expand Down