Merge "Adding GitHub skip if open issue support"

This commit is contained in:
Jenkins
2013-08-07 17:10:39 +00:00
committed by Gerrit Code Review
5 changed files with 106 additions and 0 deletions

View File

@@ -19,6 +19,7 @@ import itertools
from types import FunctionType
from unittest2 import TestCase, skip
from cafe.resources.github.issue_tracker import GitHubTracker
from cafe.resources.launchpad.issue_tracker import LaunchpadTracker
TAGS_DECORATOR_TAG_LIST_NAME = "__test_tags__"
@@ -124,4 +125,7 @@ def skip_open_issue(type, bug_id):
if type.lower() == 'launchpad' and LaunchpadTracker.is_bug_open(
bug_id=bug_id):
return skip('Launchpad Bug #{0}'.format(bug_id))
elif type.lower() == 'github' and GitHubTracker.is_bug_open(
issue_id=bug_id):
return skip('GitHub Issue #{0}'.format(bug_id))
return lambda obj: obj

View File

@@ -0,0 +1,15 @@
"""
Copyright 2013 Rackspace
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.
"""

View File

@@ -0,0 +1,31 @@
"""
Copyright 2013 Rackspace
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.
"""
from cloudcafe.common.models.configuration import ConfigSectionInterface
class GitHubConfig(ConfigSectionInterface):
SECTION_NAME = 'GITHUB'
#Access or authorization token
@property
def token(self):
return self.get('token')
#Full repository name (e.g., 'organization/repo')
@property
def repo(self):
return self.get('repo')

View File

@@ -0,0 +1,55 @@
"""
Copyright 2013 Rackspace
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 logging
from cafe.resources.github.config import GitHubConfig
from github import Github
from github.GithubException import UnknownObjectException, \
RateLimitExceededException
class GitHubTracker(object):
@classmethod
def is_bug_open(cls, issue_id):
"""Checks whether the GitHub issue for the given issue id is open.
An issue is considered open if its state is open and it does not have
a label that contains 'done' or 'complete.'
"""
config = GitHubConfig()
github = Github(login_or_token=config.token)
log = logging.getLogger('RunnerLog')
issue = None
try:
repo = github.get_repo(config.repo)
issue = repo.get_issue(int(issue_id))
except UnknownObjectException as error:
log.info('Invalid issue number or GitHub repo. '
'UnknownObjectException: {0}'.format(error))
except RateLimitExceededException as error:
log.info('Rate limit for API calls exceeded.'
'GithubException: {0}'.format(error))
if issue is None or issue.state == 'closed':
return False
labels = issue.get_labels()
for label in labels:
label = label.name.lower()
if 'done' in label or 'complete' in label:
return False
return True

View File

@@ -5,3 +5,4 @@ pymongo==2.5
argparse==1.2.1
unittest2==0.5.1
launchpadlib==1.10.2
pygithub==1.17.0