Skip to content
This repository has been archived by the owner on Oct 3, 2018. It is now read-only.

Commit

Permalink
Merge pull request #284 from novafloss/merged
Browse files Browse the repository at this point in the history
Skip closed and wrong heads
  • Loading branch information
bersace committed Feb 24, 2017
2 parents 81854a0 + 1baa083 commit 4fb8213
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
3 changes: 3 additions & 0 deletions jenkins_epo/bot.py
Expand Up @@ -110,6 +110,9 @@ def workon(self, head):
def run(self, head):
self.workon(head)

if self.current.head.payload.get('state') == 'closed':
return logger.info("Skipping closed head.")

logger.info("Listing commits from GitHub.")
payload = yield from self.current.head.fetch_commits()
self.current.commits = list(
Expand Down
15 changes: 9 additions & 6 deletions jenkins_epo/procedures.py
Expand Up @@ -17,7 +17,7 @@
import logging

from .bot import Bot
from .github import GITHUB, cached_arequest
from .github import GITHUB, cached_arequest, ApiNotFoundError
from .repository import Repository, REPOSITORIES, Head, UnauthorizedRepository
from .settings import SETTINGS
from .tasks import PrinterTask, ProcessTask, RepositoryPollerTask
Expand Down Expand Up @@ -61,8 +61,7 @@ def print_heads():
@asyncio.coroutine
def process_url(url, throttle=True):
if not match(url, Repository.heads_filter):
logger.debug("Skipping %s. Filtered.", url)
return
return logger.debug("Skipping %s. Filtered.", url)

task = asyncio.Task.current_task()
running_task = _task_map.get(url)
Expand All @@ -73,10 +72,14 @@ def process_url(url, throttle=True):

if throttle:
yield from throttle_github()
head = yield from Head.from_url(url)
try:
head = yield from Head.from_url(url)
except ApiNotFoundError:
return logger.error("No such head. Skipping.")

if head.repository not in REPOSITORIES:
logger.error("%s not managed.", head.repository)
return
return logger.error("%s not managed.", head.repository)

log_context(head)
logger.info("Working on %s.", head)

Expand Down
20 changes: 17 additions & 3 deletions tests/test_bot.py
Expand Up @@ -146,7 +146,7 @@ def test_run_extension(mocker):
bot = Bot()
assert 'ext' in bot.extensions_map

pr = Mock(name='pr')
pr = Mock(name='pr', payload=dict())
pr.fetch_commits = CoroutineMock()
commits = [Mock()]
pr.repository.process_commits.return_value = commits
Expand Down Expand Up @@ -176,7 +176,7 @@ def test_begin_skip_head(mocker):
ext.SETTINGS = {}
ext.begin.side_effect = SkipHead()

pr = Mock(name='pr')
pr = Mock(name='pr', payload=dict())
pr.fetch_commits = CoroutineMock()
commits = [Mock()]
pr.repository.process_commits.return_value = commits
Expand All @@ -189,6 +189,20 @@ def test_begin_skip_head(mocker):
assert not ext.run.mock_calls


@pytest.mark.asyncio
@asyncio.coroutine
def test_run_skip_closed(mocker):
pkg_resources = mocker.patch('jenkins_epo.bot.pkg_resources')

from jenkins_epo.bot import Bot

pkg_resources.iter_entry_points.return_value = []
pr = Mock(name='pr')
pr.payload = dict(state='closed')

yield from Bot().run(pr)


@pytest.mark.asyncio
@asyncio.coroutine
def test_run_skip_head(mocker):
Expand All @@ -204,7 +218,7 @@ def test_run_skip_head(mocker):
ext.SETTINGS = {}
ext.run.side_effect = SkipHead()

pr = Mock(name='pr')
pr = Mock(name='pr', payload=dict())
pr.fetch_commits = CoroutineMock()
commits = [Mock()]
pr.repository.process_commits.return_value = commits
Expand Down
12 changes: 12 additions & 0 deletions tests/test_procedures.py
Expand Up @@ -59,6 +59,18 @@ def test_process_url_skip(mocker, SETTINGS):
yield from process_url('url://')


@pytest.mark.asyncio
@asyncio.coroutine
def test_process_url_not_found(mocker, SETTINGS):
from_url = mocker.patch(
'jenkins_epo.procedures.Head.from_url', CoroutineMock()
)
from jenkins_epo.procedures import process_url, ApiNotFoundError
from_url.side_effect = ApiNotFoundError('url://', Mock(), Mock())

yield from process_url('url://', throttle=False)


@pytest.mark.asyncio
@asyncio.coroutine
def test_process_url(mocker, SETTINGS):
Expand Down

0 comments on commit 4fb8213

Please sign in to comment.