Skip to content

Instantly share code, notes, and snippets.

@ttx
Created January 28, 2019 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ttx/d961e307e04c42ea5d75b526f7f08061 to your computer and use it in GitHub Desktop.
Save ttx/d961e307e04c42ea5d75b526f7f08061 to your computer and use it in GitHub Desktop.
WIP checker
# Copyright 2019 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
import json
import re
import sys
import urllib.request
def get_github_PR(change_url):
match = re.search('https://github.com/(.+)/pull/(\d+)', change_url)
repository = match.group(1)
prnumber = match.group(2)
url = 'https://api.github.com/repos/%s/pulls/%s' % (repository, prnumber)
with urllib.request.urlopen(url) as link:
data = json.loads(link.read().decode())
return data
def is_wip(change):
if 'WIP' in change['title']:
print('WIP is mentioned in PR title')
return True
for label in change['labels']:
if label['name'] == 'do-not-merge':
print('PR is labeled do-not-merge')
return True
print('No WIP marker found, this PR is OK to merge')
return False
def main():
parser = argparse.ArgumentParser(description='Is the PR in WIP.')
parser.add_argument('change_url', help='GitHub PR URL')
args = parser.parse_args()
change = get_github_PR(args.change_url)
sys.exit(is_wip(change))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment