Skip to content

Commit 87a4f53

Browse files
authored
Record whether a row's Jira key is named or linked (schema 8) (#51)
1 parent 583c62f commit 87a4f53

8 files changed

Lines changed: 48 additions & 17 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ release-report:
5858
rules:
5959
- if: $CI_PIPELINE_SOURCE == "schedule"
6060
script:
61-
- uvx --from 'release-scope>=0.9,<0.10' release-scope collect --group team/backend --output public || [ $? -eq 1 ]
61+
- uvx --from 'release-scope>=0.11,<0.12' release-scope collect --group team/backend --output public || [ $? -eq 1 ]
6262
pages: true
6363
```
6464
@@ -151,7 +151,7 @@ npx skills add modern-python/release-scope
151151
```
152152

153153
The agent reads the same environment variables as the CLI, so set them first. The skill runs
154-
`release-scope>=0.9,<0.10`, the range whose flags and report schema it describes.
154+
`release-scope>=0.11,<0.12`, the range whose flags and report schema it describes.
155155

156156
## More
157157

‎docs/report.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ One row, trimmed:
3535
"tags": [{"name": "1.2.0", "url": "...", "pipeline": {"id": 201, "status": "success", "failed_jobs": []}}],
3636
"merge_requests": [{"iid": 12, "title": "SHOP-12 new endpoint", "url": "..."}],
3737
"commits": [{"sha": "c3...", "title": "Merge branch 'feature/SHOP-12'"}],
38-
"jira_keys": [{"key": "SHOP-12", "url": "https://jira.example.com/browse/SHOP-12"}],
38+
"jira_keys": [{"key": "SHOP-12", "url": "https://jira.example.com/browse/SHOP-12", "via": ["named", "linked"]}],
3939
"environments": ["preview"],
4040
"first_deployed_at": {"preview": "2026-09-22T00:00:00Z"},
4141
"main_pipeline": {"id": 103, "status": "failed", "failed_jobs": [{"kind": "job", "name": "lint", "allow_failure": false}]}
4242
}
4343
```
44+
45+
A Jira key's `via` says why the row carries it: `named` when the merge request or commit text names it, `linked`
46+
when the issue's GitLab links point into the row, or both. A candidate's keys merge `via` across the rows it ships.

‎release_scope/_candidates.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import typing
44
from urllib.parse import quote, urlencode
55

6-
from release_scope._report import Candidate, EnvironmentState, Service, Untagged
6+
from release_scope._report import Candidate, EnvironmentState, JiraKeyRef, Service, Untagged
77

88

99
_VERSION_PATTERN: typing.Final = re.compile(r"(v?)(\d+)\.(\d+)\.(\d+)")
@@ -16,7 +16,10 @@ def build_candidates(service: Service, production: EnvironmentState | None) -> l
1616
candidates: list[Candidate] = []
1717
for index, row in enumerate(service.rows):
1818
shipped = service.rows[index:]
19-
keys = {key.key: key for item in shipped if item.in_scope for key in item.jira_keys}
19+
keys: dict[str, JiraKeyRef] = {}
20+
for key in (key for item in shipped if item.in_scope for key in item.jira_keys):
21+
ref = keys.setdefault(key.key, key.model_copy(update={"via": []}))
22+
ref.via.extend(source for source in key.via if source not in ref.via)
2023
candidates.extend(
2124
Candidate(
2225
tag=tag,

‎release_scope/_report.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pydantic
66

77

8-
SCHEMA_VERSION: typing.Final = 7
8+
SCHEMA_VERSION: typing.Final = 8
99

1010

1111
class MessageCode(enum.StrEnum):
@@ -75,6 +75,7 @@ class CommitRef(pydantic.BaseModel):
7575
class JiraKeyRef(pydantic.BaseModel):
7676
key: str
7777
url: str | None
78+
via: list[typing.Literal["named", "linked"]]
7879

7980

8081
class Row(pydantic.BaseModel):
@@ -161,7 +162,7 @@ class JiraState(pydantic.BaseModel):
161162

162163

163164
class Report(pydantic.BaseModel):
164-
schema_version: typing.Literal[7] = SCHEMA_VERSION
165+
schema_version: typing.Literal[8] = SCHEMA_VERSION
165166
collected_at: dt.datetime
166167
production_environment: str
167168
services: list[Service]

‎release_scope/_use_case.py‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,15 @@ def _join_linked_issues(self, services: list[Service], state: JiraState) -> None
231231
if not links:
232232
continue
233233
for row in service.rows:
234-
named = {item.key for item in row.jira_keys}
234+
refs = {item.key: item for item in row.jira_keys}
235235
for key, link in links:
236-
if key not in named and _holds(row, link):
237-
row.jira_keys.append(JiraKeyRef(key=key, url=self._jira_url(key)))
238-
named.add(key)
236+
if not _holds(row, link):
237+
continue
238+
if key not in refs:
239+
refs[key] = JiraKeyRef(key=key, url=self._jira_url(key), via=[])
240+
row.jira_keys.append(refs[key])
241+
if "linked" not in refs[key].via:
242+
refs[key].via.append("linked")
239243
production = next(
240244
(item for item in service.environments if item.name == self.settings.production_environment), None
241245
)
@@ -547,7 +551,7 @@ def _build_row( # noqa: PLR0913
547551
merge_requests=[_merge_request_ref(item) for item in draft.merge_requests],
548552
commits=[_commit_ref(commit) for commit in draft.commits],
549553
jira_keys=[
550-
JiraKeyRef(key=key, url=self._jira_url(key))
554+
JiraKeyRef(key=key, url=self._jira_url(key), via=["named"])
551555
for key in extract_jira_keys(texts, allowed_projects=self.settings.jira_project_keys)
552556
],
553557
environments=[item.name for item in environments if item.sha in shas],

‎skills/release-scope/SKILL.md‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ description: >
1414
through uvx with this version range; it matches the flags and report schema described here:
1515

1616
```bash
17-
uvx --from 'release-scope>=0.9,<0.10' release-scope --help
17+
uvx --from 'release-scope>=0.11,<0.12' release-scope --help
1818
```
1919

2020
## Check the settings
@@ -58,7 +58,7 @@ run and only saves requests:
5858
```bash
5959
out="${XDG_CACHE_HOME:-$HOME/.cache}/release-scope"
6060
mkdir -p "$out"
61-
uvx --from 'release-scope>=0.9,<0.10' release-scope collect --project team/backend/shop \
61+
uvx --from 'release-scope>=0.11,<0.12' release-scope collect --project team/backend/shop \
6262
--output "$out/site" --cache "$out/cache.json"
6363
```
6464

@@ -83,7 +83,8 @@ Read `$out/site/report.json` and answer the user's question from it, briefly.
8383
- A row is one merged merge request or a direct commit: `merge_requests`, `commits`, `tags` pointing into it,
8484
`environments` running exactly its commit now, `first_deployed_at` (per environment other than production, when the
8585
first deploy job that shipped this row or a newer one finished), `jira_keys` (the keys its merge request or commit
86-
text names, plus, with Jira, every issue whose GitLab links point into the row), and `main_pipeline` with
86+
text names, plus, with Jira, every issue whose GitLab links point into the row; each key's `via` holds `named`,
87+
`linked`, or both, to say which), and `main_pipeline` with
8788
`failed_jobs`. Tag pipelines carry their own `failed_jobs`.
8889
- A service with no rows is up to date with production.
8990
- A service never deployed to production has a `no_production` warning; its rows run down to the first commit of the
@@ -93,7 +94,7 @@ Read `$out/site/report.json` and answer the user's question from it, briefly.
9394
highest `X.Y.Z` tag with its minor version bumped, or `null`), and `create_url`, GitLab's new-tag form for the head.
9495
It is `null` when the head is tagged or the service has no rows.
9596
- `candidates` (newest first): the tags a release could ship, each with `tag` and its `pipeline`, `rows` (how many
96-
rows run from that tag down to production), `jira_keys` (the in-scope keys of those rows, without duplicates), and
97+
rows run from that tag down to production), `jira_keys` (the in-scope keys of those rows, without duplicates, with `via` merged across them), and
9798
`compare_url`.
9899
To answer which issues a set of tags releases, merge the `jira_keys` of the picked candidates.
99100
- `jira.issues` by key: `summary`, `status`, `status_category` (anything but `done` is not done), `links` to GitLab

‎tests/test_cli.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_collect_writes_report_and_cache(gitlab: respx.Router, tmp_path: pathlib
4949
"report.json",
5050
]
5151
report: typing.Final = json.loads((output / "report.json").read_text())
52-
assert report["schema_version"] == 7
52+
assert report["schema_version"] == 8
5353
assert report["jira"] is None
5454
assert report["production_environment"] == "production"
5555
assert [len(item["rows"]) for item in report["services"]] == [5]

‎tests/test_use_case.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,25 @@ def test_issue_linked_to_a_merge_request_joins_its_row_and_the_candidates_shippi
359359
]
360360

361361

362+
def test_row_keys_record_whether_text_names_them_or_jira_links_them(jira: respx.Router) -> None:
363+
jira["jira_search"].respond(json=jira_page(*JIRA_ISSUES, jira_issue("SHOP-13", "Docs")))
364+
jira.get(f"{JIRA_ISSUE_API}/SHOP-13/remotelink").respond(
365+
json=[remote_link(f"{ENDPOINT}/team/svc/-/merge_requests/11")]
366+
)
367+
368+
service: typing.Final = _only_service(_collect(with_jira=True))
369+
370+
assert [[(key.key, key.via) for key in row.jira_keys] for row in service.rows[:3]] == [
371+
[("SHOP-9", ["named"])],
372+
[("SHOP-12", ["named", "linked"]), ("SHOP-13", ["named"])],
373+
[("SHOP-13", ["linked"])],
374+
]
375+
assert [(key.key, key.via) for key in service.candidates[0].jira_keys] == [
376+
("SHOP-12", ["named", "linked"]),
377+
("SHOP-13", ["named", "linked"]),
378+
]
379+
380+
362381
@pytest.mark.httpx2(assert_all_called=False)
363382
def test_issue_linked_to_a_commit_joins_the_row_holding_it(jira: respx.Router) -> None:
364383
jira["commits"].respond(json=[commit("abcdef1234", "Hotfix", date="2026-09-25T00:00:00Z"), *COMMITS[1:]])

0 commit comments

Comments
 (0)