Skip to content

Commit

Permalink
Support job_recipe in component-config.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
kkaarreell committed Mar 15, 2024
1 parent 9d16123 commit fb1640e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
9 changes: 9 additions & 0 deletions component-config.yaml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,12 @@ issues:
id: subtask_rpminspect
parent: errata_task
on_respin: close

- summary: "regression testing"
description: "Run automated tests"
assignee: '{{ ERRATUM.people_assigned_to }}'
type: subtask
id: subtask_regression
parent: errata_task
on_respin: close
job_recipe: https://path/to/recipe.yaml
23 changes: 22 additions & 1 deletion newa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,19 @@ class Erratum(Cloneable, Serializable):
""" An eratum """

release: str
# builds: list[...] = ...
builds: list[str] = []

def fetch_details(self) -> None:
raise NotImplementedError

@define
class Recipe(Cloneable, Serializable):
""" A job recipe """

url: str

def fetch_details(self) -> None:
raise NotImplementedError

@define
class Job(Cloneable, Serializable):
Expand Down Expand Up @@ -185,6 +193,18 @@ def id(self) -> str:
return f'{self.event.id} @ {self.erratum.release}'


@define
class JiraJob(ErratumJob):
""" A single *jira* job """

recipe: Optional[Recipe] = field( # type: ignore[var-annotated]
converter=lambda x: None if x is None else x if isinstance(x, Recipe) else Recipe(**x),
)

@property
def id(self) -> str:
return f'{self.event.id} @ {self.erratum.release}'

#
# Component configuration
#
Expand All @@ -210,6 +230,7 @@ class IssueAction: # type: ignore[no-untyped-def]
converter=lambda value: OnRespinAction(value) if value else None)
type: IssueType = field(converter=IssueType)
parent: Optional[str] = None
job_recipe: Optional[str] = None


@define
Expand Down
17 changes: 12 additions & 5 deletions newa/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import click
from attrs import define

from . import Erratum, ErratumConfig, ErratumJob, Event, EventType, InitialErratum, render_template
from . import Erratum, ErratumConfig, ErratumJob, Event, EventType, InitialErratum, JiraJob, Recipe, render_template

logging.basicConfig(
format='%(asctime)s %(message)s',
Expand Down Expand Up @@ -142,6 +142,7 @@ def cmd_jira(ctx: CLIContext) -> None:
print(f'* Would create a {action.type.name} issue:')
print(f' summary: {action.summary}')
print(f' summary: {action.description}')
print()

if action.id in known_issues:
raise Exception(f'Issue "{action.id}" is already created!')
Expand All @@ -153,7 +154,6 @@ def cmd_jira(ctx: CLIContext) -> None:
issue_actions.append(action)
continue

print()
print(f' Issue would be assigned to {action.assignee}.')
print(f' rendered: >>{render_template(action.assignee, ERRATUM=erratum_job)}<<')
print(f' Will remember the issue as `{action.id}`.')
Expand All @@ -163,11 +163,18 @@ def cmd_jira(ctx: CLIContext) -> None:

known_issues[action.id] = True

if action.job_recipe:
print(f'* Would kick automated job for issue {action.type.name} based on recipe from {action.job_recipe}:')
print()

jira_job = JiraJob(event=erratum_job.event, erratum=erratum_job.erratum, recipe=Recipe(url = action.job_recipe))

else:
jira_job = JiraJob(event=erratum_job.event, erratum=erratum_job.erratum, recipe=None)

# erratum_job.issue = ...
# what's recipe? doesn't it belong to "schedule"?
# recipe = new JobRecipe(url)

ctx.save_erratum_job('jira-', erratum_job)
ctx.save_erratum_job('jira-', jira_job)


@main.command(name='schedule')
Expand Down

0 comments on commit fb1640e

Please sign in to comment.