Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

address #56 and change commit formatting to look more like the git hook #57

Open
wants to merge 1 commit into from

2 participants

@Dav1dde

This removes the omit phase options, it will always be the shown.
Adds what was requested in #56 (filtering for status), also changing the the BooleanFields to SelectMultipleField.

@TkTech
Owner

Thanks for these changes, but I think it's a good idea to start requiring at least basic tests (using nosetest), especially since I have no Jenkins setup floating around to test. I'm thinking /tests, /tests/data/. /tests/data/ will have payload examples used in the tests. For the hooks, the tests are simple. Make a fake request, check the response.

@TkTech
Owner

Thoughts?

@Dav1dde

I can definitely add tests to an existing infrastructure, since I never really worked with one of the bigger unittesting-frameworks apart from the std. unittest, I don't really know how that would look.

I imagine the tests (for Hooks) would require an easy way of influencing the parameters of handle_request, if that is in place, adding tests should be pretty easy and fast.

PS: I fixed the comment-issue and rebased the commits

@Dav1dde

So what is the current state? Tests?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 52 additions and 66 deletions.
  1. +52 −66 notifico/services/hooks/jenkins.py
View
118 notifico/services/hooks/jenkins.py
@@ -9,35 +9,32 @@
class JenkinsConfigForm(wtf.Form):
- print_started = wtf.BooleanField('Print Started', validators=[
- wtf.Optional()
- ], default=False, description=(
- 'If checked, sends a message for every started job.'
+ phase = wtf.SelectMultipleField('Phase',
+ default=['finished'],
+ choices=[
+ ('started', 'Started'),
+ ('completed', 'Completed'),
+ ('finished', 'Finished')
+ ],
+ description=(
+ 'Print messages for selected fields.'
))
- print_completed = wtf.BooleanField('Print Completed', validators=[
- wtf.Optional()
- ], default=False, description=(
- 'If checked, sends a message for every completed job.'
- ))
-
- print_finished = wtf.BooleanField('Print Finished', validators=[
- wtf.Optional()
- ], default=True, description=(
- 'If checked, sends a message for every finished job.'
- ))
-
- omit_phase = wtf.BooleanField('Omit Phase', validators=[
- wtf.Optional()
- ], default=True, description=(
- 'If checked, does not add the job\'s current phase to the message. '
- 'Recommended if only one of the above is checked.'
+ status = wtf.SelectMultipleField('Status',
+ default=['success', 'unstable', 'failure'],
+ choices=[
+ ('success', 'Success'),
+ ('unstable', 'Unstable'),
+ ('failure', 'Failure')
+ ],
+ description=(
+ 'Print messages for selected fields.'
))
use_colors = wtf.BooleanField('Use Colors', validators=[
wtf.Optional()
], default=True, description=(
- 'If checked, commit messages will include minor mIRC coloring.'
+ 'If checked, messages will include minor mIRC coloring.'
))
@@ -62,17 +59,21 @@ def handle_request(cls, user, request, hook):
if not payload:
return
- phases = {
- 'STARTED': hook.config.get('print_started', False),
- 'COMPLETED': hook.config.get('print_completed', False),
- 'FINISHED': hook.config.get('print_finished', True)
- }
- if not phases.get(payload['build']['phase'], False):
+ phase = payload['build']['phase'].lower()
+ if not phase in hook.config.get('phase', []):
+ return
+
+ status = payload['build'].get('status', 'SUCCESS').lower()
+ # yeah documentation of the plugin differs
+ # from the actual implementation?
+ if status == 'failed':
+ status = 'failure'
+ if not status in hook.config.get('status', []):
return
- omit_phase = hook.config.get('omit_phase', False)
+
strip = not hook.config.get('use_colors', True)
- summary = cls._create_summary(payload, omit_phase)
+ summary = cls._create_summary(payload)
yield cls.message(summary, strip)
@@ -88,54 +89,39 @@ def _prefix_line(cls, line, payload):
return prefix + line
@classmethod
- def _create_summary(cls, payload, omit_phase=False):
+ def _create_summary(cls, payload):
"""
Create and return a one-line summary of the build
"""
status_colour = {
'SUCCESS': HookService.colors['GREEN'],
- 'UNSTABLE': HookService.colors['YELLOW'],
+ 'UNSTABLE': HookService.colors['ORANGE'],
+ # documentation differs from implementation
+ 'FAILURE' : HookService.colors['RED'],
'FAILED': HookService.colors['RED']
}.get(
payload['build'].get('status', 'SUCCESS'),
HookService.colors['RED']
)
- lines = []
-
- # Build number
- lines.append(u'Jenkins CI - build #{number}'.format(
- project=payload['name'],
- number=payload['build']['number'],
- ))
-
- # Status
- status = u''
- if 'status' in payload['build']:
- status = u'{status_colour}{message}{RESET}'.format(
- status_colour=status_colour,
- message=payload['build']['status'].capitalize(),
- **HookService.colors
- )
-
- # Current phase
- phase = u''
- if not omit_phase:
- phase = u'{status_colour}{message}{RESET}'.format(
- status_colour=status_colour,
- message=payload['build']['phase'].capitalize(),
- **HookService.colors
- )
-
- lines.append(' | '.join(filter(bool, [phase, status])))
-
- # URL to build
- lines.append(u'{PINK}{url}{RESET}'.format(
- url=payload['build']['full_url'],
- **HookService.colors
- ))
+ number = payload['build']['number']
+ phase = payload['build']['phase'].lower()
+ status = payload['build']['status'].lower()
+ url = payload['build']['full_url']
- line = u' '.join(lines)
+ fmt_string = (
+ '{ORANGE}jenkins{RESET} built {status_colour}#{number}{RESET} '
+ '{phase} ({status_colour}{status}{RESET}) {PINK}{url}{RESET}'
+ )
+
+ line = fmt_string.format(
+ status_colour=status_colour,
+ number=number,
+ phase=phase,
+ status=status,
+ url=url,
+ **HookService.colors
+ )
return cls._prefix_line(line, payload)
@classmethod
Something went wrong with that request. Please try again.