Skip to content

Commit 0f4d7fe

Browse files
authored
List services never deployed to production, walking their whole default branch (#16)
1 parent 62ce628 commit 0f4d7fe

6 files changed

Lines changed: 46 additions & 25 deletions

File tree

‎README.md‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
Jira issues, failed jobs.
2222

2323
For every service it reads the latest successful production deployment, walks the default branch down to that
24-
commit, and writes a static site with one JSON report: a row per merge request or direct commit, newest first, with the tags that
25-
point into it, the environments running it, the Jira keys its MR mentions, and the failed jobs of its main-branch
26-
and tag pipelines. With a Jira token, it also reads the summary and status of every key in one batched search,
24+
commit, or down to its first commit when the service was never deployed to production, and writes a static site with
25+
one JSON report: a row per merge request or direct commit, newest first, with the tags that point into it, the
26+
environments running it, the Jira keys its MR mentions, and the failed jobs of its main-branch and tag pipelines. With a Jira token, it also reads the summary and status of every key in one batched search,
2727
and the GitLab merge requests and commits linked to each issue. GitLab's Jira integration adds those links to the
2828
issue's Web links whenever a commit or MR mentions it; a link counts only if it starts with
2929
`RELEASE_SCOPE_GITLAB__ENDPOINT`. The projects they point to are the issue's related services.
@@ -87,7 +87,8 @@ The report is versioned by `schema_version`; the models live in
8787
Top-level `jira` is `null` without a Jira token; otherwise it holds `issues` by key (summary, status, status category,
8888
issue type, linked GitLab changes), the `missing` keys Jira did not return, and an `error` if a Jira request failed.
8989
Each service lists its `candidates`: the tags a release could ship, newest first, each with its pipeline, the number of
90-
rows it ships, the in-scope Jira keys of those rows, and the compare link from production. One row, trimmed:
90+
rows it ships, the in-scope Jira keys of those rows, and the compare link from production, or the tag's commit history
91+
when the service has no production deployment. One row, trimmed:
9192

9293
```json
9394
{
@@ -107,14 +108,14 @@ Besides `report.json`, `collect` writes `index.html` and its script into the out
107108
installed package and change only with it, so the page always matches the report schema. The page loads
108109
`report.json` from next to itself; it needs a web server, not a `file://` URL.
109110

110-
**Services** lists every service with a production deployment, and every service that failed to collect, as one
111-
line: what production runs, the picked tag, how many merge requests or commits and Jira tasks it ships, failed jobs
111+
**Services** lists every service with a production deployment or with rows, and every service that failed to collect,
112+
as one line: what production runs, the picked tag, how many merge requests or commits and Jira tasks it ships, failed jobs
112113
with the ones allowed to fail counted apart, and a mark when the range was cut at `RELEASE_SCOPE_MAX_COMMITS`.
113114
Opening a line shows the service's environments, warnings, merge requests that are not merged yet, and its rows with
114115
tags and their pipelines, merge requests or commits, Jira keys with their status, environments, and failed jobs; rows
115116
out of scope are dimmed. Links open in a new tab. Each tag has a **pick** button:
116117
picking it highlights the rows it ships and closes the line again. A `--jira` report starts with each service's
117-
release tag picked. Services without a production deployment are left out of the page.
118+
release tag picked. Services with neither a production deployment nor rows are left out of the page.
118119

119120
The address keeps the picks after `#`, as `team/api=2.4.0&team/web=5.12.0`, so sharing or reloading the page keeps
120121
them. An address with picks replaces the release tags of a `--jira` report; picks that are not in the report, such as
@@ -128,7 +129,8 @@ text box to copy from by hand, since browsers allow the copy button only over HT
128129
summary and a status badge: grey to do, blue in progress, green done. Copy them one per line or as a JQL
129130
`key in (...)` clause, each in its own box.
130131
- **Tag pipelines**: the pipeline of each picked tag, as a Markdown list.
131-
- **Compare**: a GitLab compare link per service from production to the picked tag, as a Markdown list.
132+
- **Compare**: a GitLab compare link per service from production to the picked tag, as a Markdown list. A service
133+
never deployed to production gets the commit history of the tag instead.
132134
- **Release post**: one Markdown text with a line per picked tag, holding its compare link and pipeline, followed by
133135
the Jira tasks with their summaries.
134136

‎release_scope/_candidates.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@
33
from release_scope._report import Candidate, EnvironmentState, Service
44

55

6-
def build_candidates(service: Service, production: EnvironmentState) -> list[Candidate]:
7-
base: str = quote(production.ref if production.tag else production.sha)
6+
def build_candidates(service: Service, production: EnvironmentState | None) -> list[Candidate]:
7+
base: str | None = None
8+
if production is not None:
9+
base = quote(production.ref if production.tag else production.sha)
810
candidates: list[Candidate] = []
911
for index, row in enumerate(service.rows):
1012
shipped = service.rows[index:]
1113
keys = {key.key: key for item in shipped if item.in_scope for key in item.jira_keys}
1214
candidates.extend(
1315
Candidate(
1416
tag=tag,
15-
compare_url=f"{service.project_url}/-/compare/{base}...{quote(tag.name)}",
17+
compare_url=f"{service.project_url}/-/compare/{base}...{quote(tag.name)}"
18+
if base
19+
else f"{service.project_url}/-/commits/{quote(tag.name)}",
1620
rows=len(shipped),
1721
jira_keys=list(keys.values()),
1822
)

‎release_scope/_static/index.html‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ <h1 x-text="report.jira_scope.length ? 'Release scope: ' + report.jira_scope.joi
9393
<h2>Services</h2>
9494
<p x-show="pickable.length" class="muted">Open a service and pick the tag to release: it ships every merge request and commit from its row down to production. The address keeps the picks, so share it to share them.</p>
9595
<p x-show="ignored" class="warn" x-text="ignored"></p>
96-
<template x-for="service in deployed" :key="service.project">
96+
<template x-for="service in listed" :key="service.project">
9797
<details class="service" name="services">
9898
<summary>
9999
<span class="name" x-text="service.project"></span>
@@ -298,11 +298,11 @@ <h3>Release post</h3>
298298
get collectedAt() {
299299
return this.report.collected_at.slice(0, 16).replace("T", " ");
300300
},
301-
get deployed() {
302-
return this.report.services.filter((service) => service.error || this.production(service));
301+
get listed() {
302+
return this.report.services.filter((service) => service.error || this.production(service) || service.rows.length);
303303
},
304304
get pickable() {
305-
return this.deployed.filter((service) => service.candidates.length);
305+
return this.listed.filter((service) => service.candidates.length);
306306
},
307307
get problems() {
308308
const jira = this.report.jira;
@@ -432,10 +432,11 @@ <h3>Release post</h3>
432432
},
433433
productionRef(service) {
434434
const production = this.production(service);
435-
if (!production) return "";
435+
if (!production) return "not in production";
436436
return production.tag ? production.ref : production.sha.slice(0, 8);
437437
},
438438
compareLabel({ service, candidate }) {
439+
if (!this.production(service)) return `commits to ${candidate.tag.name}`;
439440
return `${this.productionRef(service)}...${candidate.tag.name}`;
440441
},
441442
pipelineIcon(pipeline) {

‎release_scope/_use_case.py‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,14 @@ def _collect_service(self, project: Project, cache: Cache, *, links: list[Linked
251251
service.warnings.append("Project has no default branch.")
252252
return service
253253
if production is None:
254-
service.warnings.append(f"No successful deployment to '{self.settings.production_environment}'.")
255-
return service
254+
service.warnings.append(
255+
f"No successful deployment to '{self.settings.production_environment}'; "
256+
f"rows run from the first commit of {project.default_branch}."
257+
)
256258

257-
walk: typing.Final = self._walk(project, project.default_branch, production.sha, service, cache)
259+
walk: typing.Final = self._walk(
260+
project, project.default_branch, production.sha if production else None, service, cache
261+
)
258262
drafts, linked, in_scope = walk.drafts, [False] * len(walk.drafts), [True] * len(walk.drafts)
259263
if links is not None:
260264
drafts, linked, in_scope = self._scope_rows(project, project.default_branch, service, walk, links, cache)
@@ -272,9 +276,13 @@ def _collect_service(self, project: Project, cache: Cache, *, links: list[Linked
272276
service.candidates.extend(build_candidates(service, production))
273277
return service
274278

275-
def _walk(self, project: Project, default_branch: str, baseline: str, service: Service, cache: Cache) -> _Walk:
279+
def _walk(
280+
self, project: Project, default_branch: str, baseline: str | None, service: Service, cache: Cache
281+
) -> _Walk:
276282
commits, truncated = self.api.list_first_parent_commits(
277-
project.id, f"{baseline}..{default_branch}", max_items=self.settings.max_commits
283+
project.id,
284+
f"{baseline}..{default_branch}" if baseline else default_branch,
285+
max_items=self.settings.max_commits,
278286
)
279287
walk: typing.Final = _Walk(truncated=truncated)
280288
service.truncated = truncated

‎skills/release-scope/SKILL.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ Read `$out/site/report.json` and answer the user's question from it, briefly.
8181
`environments` already running it, `jira_keys`, and `main_pipeline` with `failed_jobs`. Tag pipelines carry their
8282
own `failed_jobs`.
8383
- A service with no rows is up to date with production.
84+
- A service never deployed to production has a warning saying so; its rows run down to the first commit of the
85+
default branch and its `compare_url` lists the tag's commits.
8486
- `truncated: true`: the walk stopped at `RELEASE_SCOPE_MAX_COMMITS`, so the oldest candidates miss rows and keys.
8587
- `candidates` (newest first): the tags a release could ship, each with `tag` and its `pipeline`, `rows` (how many
8688
rows run from that tag down to production), `jira_keys` (the in-scope keys of those rows, without duplicates), and

‎tests/test_use_case.py‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -476,14 +476,18 @@ def test_project_listed_twice_is_collected_once(gitlab: respx.Router) -> None:
476476
assert [item.project for item in report.services] == ["team/svc"]
477477

478478

479-
@pytest.mark.httpx2(assert_all_called=False)
480-
def test_service_without_production_deployment_has_no_rows(gitlab: respx.Router) -> None:
479+
def test_service_without_production_deployment_lists_the_whole_default_branch(gitlab: respx.Router) -> None:
481480
gitlab["deploy:production"].respond(json=[])
482481

483482
service: typing.Final = _only_service(_collect())
484483

485-
assert service.rows == []
486-
assert service.warnings == ["No successful deployment to 'production'."]
484+
assert gitlab["commits"].calls[0].request.url.params["ref_name"] == "main"
485+
assert [row.commits[0].sha for row in service.rows] == ["head", "c3", "c2", "c1", "c0b"]
486+
assert [(item.tag.name, item.rows, item.compare_url) for item in service.candidates] == [
487+
("1.2.0", 4, f"{ENDPOINT}/team/svc/-/commits/1.2.0"),
488+
("1.1.0", 2, f"{ENDPOINT}/team/svc/-/commits/1.1.0"),
489+
]
490+
assert service.warnings == ["No successful deployment to 'production'; rows run from the first commit of main."]
487491

488492

489493
@pytest.mark.httpx2(assert_all_called=False)

0 commit comments

Comments
 (0)