Skip to content

Commit

Permalink
graphql: scheduleBuild: add flag for repos
Browse files Browse the repository at this point in the history
Add a new isRepo parameter to the scheduleBuild mutation. If passed and
is true the name ("machine") given is taken to be a repo and a repo job
is scheduled to build instead of a machine job.
  • Loading branch information
enku committed Sep 16, 2024
1 parent c1e1b40 commit adee523
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/gentoo_build_publisher/graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,13 @@ def resolve_mutation_schedule_build(
_obj: Any,
_info: Info,
machine: str,
isRepo: bool = False,
params: list[BuildParameterInput] | None = None,
) -> str | None:
params = params or []
job = f"repos/job/{machine}" if isRepo else machine

return publisher.schedule_build(machine, **{p["name"]: p["value"] for p in params})
return publisher.schedule_build(job, **{p["name"]: p["value"] for p in params})


@mutation.field("keepBuild")
Expand Down
2 changes: 1 addition & 1 deletion src/gentoo_build_publisher/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ type Query {
type Mutation {
publish(id: ID!): MachineSummary
pull(id: ID!, note: String, tags: [String!]): MachineSummary
scheduleBuild(machine: String!, params: [BuildParameter!]): String
scheduleBuild(machine: String!, isRepo: Boolean = false, params: [BuildParameter!]): String
keepBuild(id: ID!): Build
createBuildTag(id: ID!, tag: String!) : Build!
removeBuildTag(machine: String!, tag: String!) : MachineSummary
Expand Down
15 changes: 15 additions & 0 deletions tests/test_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,21 @@ def test_should_return_error_when_schedule_build_fails(self) -> None:
self.assertEqual(result, expected)
mock_schedule_build.assert_called_once_with("babette")

def test_with_repos(self) -> None:
query = 'mutation { scheduleBuild(machine: "gentoo", isRepo: true) }'

with mock.patch.object(publisher, "schedule_build") as mock_schedule_build:
mock_schedule_build.return_value = (
"https://jenkins.invalid/queue/item/31528/"
)
result = graphql(self.fixtures.client, query)

self.assertEqual(
result,
{"data": {"scheduleBuild": "https://jenkins.invalid/queue/item/31528/"}},
)
mock_schedule_build.assert_called_once_with("repos/job/gentoo")


@fixture.requires("tmpdir", "publisher", "client")
class KeepBuildMutationTestCase(TestCase):
Expand Down

0 comments on commit adee523

Please sign in to comment.