Rank an issue the loop files in Jira by its score among the issues the loop filed, a security finding first
CI / tests (pull_request) Successful in 2m8s
CI / tests (pull_request) Successful in 2m8s
This commit is contained in:
+85
-18
@@ -2,7 +2,7 @@
|
||||
|
||||
An item is an open child issue. Its ID is the issue's number, so every child must be in the epic's own Jira project: ABC-34 is item 34 of the plan under ABC-12. The summary is the tagline, the description the detail, the earliest Fix Version the release, and an "is blocked by" link a blocker. L, E, I, S, Moves and Exempt sit in one issue property, PROPERTY, which needs no Jira admin to set up; an issue a person filed holds none, and reads as an item without scores.
|
||||
|
||||
`add` files an item as a new child issue, marked with FILED_BY, and `finish` moves an item's issue to a done status. `edit` changes an issue the loop filed, but never its links. Of an issue a person filed it sets only the scores, with a comment that tells the team why."""
|
||||
`add` files an item as a new child issue, marked with FILED_BY, and ranks it among the issues the loop filed, by the score the config's formula gives, as `placing` says. `finish` moves an item's issue to a done status. `edit` changes an issue the loop filed, but never its links. Of an issue a person filed it sets only the scores, with a comment that tells the team why."""
|
||||
import base64
|
||||
import dataclasses
|
||||
import pathlib
|
||||
@@ -13,10 +13,11 @@ from adf_codec.convert import adfs_to_markdown, markdown_to_adf, Refused
|
||||
from release_plan.todo_table import BLOCKED_BY, EXEMPTIONS, is_exempt, Item, MOVES, parse_ids, parse_moves, parse_scores, SHAPE
|
||||
from plan_store.markdown_edits import bold_cell, plain, unfit_text
|
||||
from plan_store.stores import cells, Plan, Written
|
||||
from project_config.settings import Epic, Finish, JIRA_FINISH_STATUS, JIRA_FINISH_TRANSITION
|
||||
from project_config.settings import Epic, Finish, JIRA_FINISH_STATUS, JIRA_FINISH_TRANSITION, JIRA_SCORE_BAR, JIRA_SCORE_FORMULA
|
||||
from failure import Failure
|
||||
from rest_client import json_request
|
||||
from release_plan.release import parsed, Release, tagged
|
||||
from release_plan import ranking
|
||||
from rest_client.env_file import read_env
|
||||
|
||||
# One pair of keys for Jira and Confluence: one Atlassian account's API token opens both.
|
||||
@@ -55,6 +56,11 @@ ToMarkdown = typing.Callable[[list[dict[str, typing.Any]]], list[str] | Refused
|
||||
ToAdf = typing.Callable[[str], dict[str, typing.Any] | Failure]
|
||||
|
||||
|
||||
class ReadsScoring(typing.Protocol):
|
||||
def read(self) -> ranking.Scoring | Failure:
|
||||
"""The scoring `add` scores an item by: the config's formula and bar, with the goal weights that the goals file, the decision log and the comprehension history give."""
|
||||
|
||||
|
||||
def http_json(method: str, url: str, authorization: str, body: object) -> object:
|
||||
return json_request.http_json(method, url, authorization, body, TIMEOUT, error_message)
|
||||
|
||||
@@ -95,6 +101,8 @@ class JiraPlan:
|
||||
to_adf: ToAdf = markdown_to_adf
|
||||
# How a finished item moves; None where the config doesn't say, and then `finish` is a Failure.
|
||||
finish_by: Finish | None = None
|
||||
# None where the config states no formula and bar, and then `add` is a Failure.
|
||||
scoring: ReadsScoring | None = None
|
||||
|
||||
@property
|
||||
def label(self) -> str:
|
||||
@@ -115,12 +123,20 @@ class JiraPlan:
|
||||
return next((issue for issue in issues if isinstance(issue, Failure)), None) or plan_of([issue for issue in issues if isinstance(issue, Issue)], self.epic, self.to_markdown)
|
||||
|
||||
def add(self, fields: dict[str, str], detail: str) -> Written | Failure:
|
||||
"""Files the item as a child issue, which Jira ranks last in the backlog. No bar applies and the goals file isn't read, since a plan in Jira has no place for a formula or a bar yet (todo.md's item 384).
|
||||
"""Files the item as a child issue, where it scores at the config's bar or above or is exempt, and ranks it as `placing` says.
|
||||
|
||||
Jira takes the links after the issue. A link it refuses leaves the issue filed, so the write counts as landed, and a note names each link to make by hand."""
|
||||
Jira takes the links and the rank after the issue. One it refuses leaves the issue filed, so the write counts as landed, and a note says what to do by hand."""
|
||||
filing = filing_of(fields, detail, self.epic)
|
||||
if isinstance(filing, Failure):
|
||||
return filing
|
||||
if self.scoring is None:
|
||||
return Failure(f"the config states no formula and bar to score the item by: set `{JIRA_SCORE_FORMULA}` and `{JIRA_SCORE_BAR}`, as `project-config --help` shows")
|
||||
scoring = self.scoring.read()
|
||||
if isinstance(scoring, Failure):
|
||||
return Failure(f"cannot score the item to file: {scoring.reason}")
|
||||
value = filed_score(filing.item, scoring)
|
||||
if isinstance(value, Failure):
|
||||
return value
|
||||
authorization = basic_auth(self.env_file)
|
||||
if isinstance(authorization, Failure):
|
||||
return authorization
|
||||
@@ -133,8 +149,14 @@ class JiraPlan:
|
||||
version = self.fix_version(filing.release, authorization)
|
||||
if isinstance(version, Failure):
|
||||
return version
|
||||
if filing.blockers and (missing := self.missing_blocker(filing.blockers, authorization)):
|
||||
return missing
|
||||
answered = children(self.epic, authorization, self.http)
|
||||
if isinstance(answered, Failure):
|
||||
return answered
|
||||
held = {raw.get("key") for raw in answered if isinstance(raw, dict)}
|
||||
# `item` reads only an open child as a blocker, so a link to any other issue would be lost on the next read.
|
||||
if missing := next((blocker for blocker in filing.blockers if blocker not in held), None):
|
||||
return Failure(f"{self.label} holds no item {number(missing)} to be blocked by")
|
||||
before = placing(answered, filing.item, value, scoring)
|
||||
created = self.http("POST", f"{self.epic.site}/rest/api/3/issue", authorization, {"fields": issue_fields | {"fixVersions": [{"name": version}]}, "properties": [{"key": PROPERTY, "value": filing.scores}]})
|
||||
if isinstance(created, Failure):
|
||||
return Failure(f"cannot file the item under {self.epic.key}: {created.reason}; {PERHAPS_FILED.format(epic=self.epic.key)}")
|
||||
@@ -147,8 +169,21 @@ class JiraPlan:
|
||||
linked = self.http("POST", f"{self.epic.site}/rest/api/3/issueLink", authorization, {"type": {"name": BLOCKS}, "inwardIssue": {"key": blocker}, "outwardIssue": {"key": key}})
|
||||
if isinstance(linked, Failure):
|
||||
notes.append(f"filed {key}, but cannot link it as blocked by {blocker}: {linked.reason}; link it in Jira")
|
||||
if isinstance(before, Failure):
|
||||
notes.append(f"filed {key}, but cannot rank it: {before.reason}; rank it in Jira")
|
||||
elif before is not None and (refused := self.rank_refusal(key, before, authorization)):
|
||||
notes.append(f"filed {key}, but cannot rank it before {before}: {refused}; rank it in Jira")
|
||||
return Written(number(key), tuple(notes))
|
||||
|
||||
def rank_refusal(self, key: str, before: str, authorization: str) -> str | None:
|
||||
"""Ranks the issue named key just before the issue named before; why Jira refused, or None where it didn't. Jira answers a rank it made with no body, and one it refused with an error, or with an entry per issue that holds the errors."""
|
||||
answer = self.http("PUT", f"{self.epic.site}/rest/agile/1.0/issue/rank", authorization, {"issues": [key], "rankBeforeIssue": before})
|
||||
if isinstance(answer, Failure):
|
||||
return answer.reason
|
||||
entries = answer.get("entries") if isinstance(answer, dict) else None
|
||||
refused = [entry for entry in entries if isinstance(entry, dict) and entry.get("status") != 200] if isinstance(entries, list) else []
|
||||
return "; ".join(str(error) for entry in refused for error in entry.get("errors") or [f"Jira answered {entry.get('status')}"]) or None
|
||||
|
||||
def fix_version(self, release: str, authorization: str) -> str | Failure:
|
||||
"""The name of the Jira project's Fix Version for release, which a project may spell with a leading v, as `earliest_release` reads it."""
|
||||
project = project_of(self.epic.key)
|
||||
@@ -158,14 +193,6 @@ class JiraPlan:
|
||||
names = {name for version in versions if isinstance(version, dict) and isinstance(name := version.get("name"), str)} if isinstance(versions, list) else set()
|
||||
return next((name for name in (release, f"v{release}") if name in names), None) or Failure(f"the Jira project {project} has no Fix Version {release} or v{release}; create it in Jira, or name a release it has")
|
||||
|
||||
def missing_blocker(self, blockers: tuple[str, ...], authorization: str) -> Failure | None:
|
||||
"""A Failure naming the first of blockers that is no open child of the epic. `item` reads only an open child as a blocker, so a link to any other issue would be lost on the next read."""
|
||||
answered = children(self.epic, authorization, self.http)
|
||||
if isinstance(answered, Failure):
|
||||
return answered
|
||||
held = {raw.get("key") for raw in answered if isinstance(raw, dict)}
|
||||
return next((Failure(f"{self.label} holds no item {number(blocker)} to be blocked by") for blocker in blockers if blocker not in held), None)
|
||||
|
||||
def edit(self, id_: int, fields: dict[str, str], detail: str | None, comment: str | None = None) -> Written | Failure:
|
||||
"""Sets the fields and the detail in one request, so Jira takes all of the edit or none, and then posts comment on the issue. `revision_of` says what an edit may set.
|
||||
|
||||
@@ -243,6 +270,8 @@ class Filing:
|
||||
scores: dict[str, typing.Any]
|
||||
# The key of each issue the item is blocked by.
|
||||
blockers: tuple[str, ...]
|
||||
# The item as ranking scores it, under the ID 0, since Jira numbers it once filed.
|
||||
item: Item
|
||||
|
||||
|
||||
def filing_of(fields: dict[str, str], detail: str, epic: Epic) -> Filing | Failure:
|
||||
@@ -254,15 +283,16 @@ def filing_of(fields: dict[str, str], detail: str, epic: Epic) -> Filing | Failu
|
||||
if unfit := unfit_text(summary, detail):
|
||||
return unfit
|
||||
release = named.get("Release", "")
|
||||
if parsed(release) is None:
|
||||
version = parsed(release)
|
||||
if version is None:
|
||||
return Failure(f"the item's Release {release!r} is not a version such as 1.2.0")
|
||||
# Named so the shared messages read "item to file's L": they open with "item" and an ID, which this item has none of yet.
|
||||
levels = parse_scores("to file", named, SHAPE.score_columns)
|
||||
if isinstance(levels, Failure):
|
||||
return levels
|
||||
moves, exempt = named.get(MOVES, ""), named.get("Exempt", "")
|
||||
if isinstance(unfit_moves := parse_moves("to file", moves), Failure):
|
||||
return unfit_moves
|
||||
if isinstance(parsed_moves := parse_moves("to file", moves), Failure):
|
||||
return parsed_moves
|
||||
if not is_exempt(exempt):
|
||||
return Failure(f"the item's Exempt {exempt!r} is not empty or one of {', '.join(EXEMPTIONS[1:])}")
|
||||
blockers = parse_ids(named.get(BLOCKED_BY, ""))
|
||||
@@ -273,7 +303,44 @@ def filing_of(fields: dict[str, str], detail: str, epic: Epic) -> Filing | Failu
|
||||
if exempt == SECURITY:
|
||||
issue_fields["labels"] = [SECURITY]
|
||||
value = levels | {MOVES: moves, "Exempt": exempt, FILED_BY[0]: FILED_BY[1]}
|
||||
return Filing(issue_fields, release, value, tuple(f"{project}-{blocker}" for blocker in blockers))
|
||||
return Filing(issue_fields, release, value, tuple(f"{project}-{blocker}" for blocker in blockers), Item(0, version, exempt, summary, levels, parsed_moves, blockers))
|
||||
|
||||
|
||||
def filed_score(item: Item, scoring: ranking.Scoring) -> float | Failure:
|
||||
"""The item's score, or why it may not be filed: it lacks a score the formula may use, names a goal it may not, or scores under the bar without being exempt."""
|
||||
if missing := next((name for name in SET_SCORES if name not in item.scores), None):
|
||||
return Failure(f"the item to file has no {missing}: score it on {', '.join(SET_SCORES[:-1])} and {SET_SCORES[-1]}")
|
||||
value = ranking.item_score(item, scoring, "the item to file")
|
||||
if not isinstance(value, Failure) and not item.exempt and round(value, 1) < scoring.bar:
|
||||
return Failure(f"the item to file scores {value:.1f}, under the bar {scoring.bar:g}; don't file it, or mark it with a reason the bar doesn't apply")
|
||||
return value
|
||||
|
||||
|
||||
def placing(answered: list[object], new: Item, value: float, scoring: ranking.Scoring) -> str | None | Failure:
|
||||
"""The key of the issue to rank the new item, which scores value, just before; None where it stays last, where Jira files it. answered is the epic's open children in backlog order.
|
||||
|
||||
Only the issues the loop filed count, so the team's rank of every other issue stays as it is. A security finding goes before the first of them that isn't one, and any other item before the first that isn't one and scores lower, as todo.md ranks its items."""
|
||||
for raw in answered:
|
||||
issue = issue_of(raw)
|
||||
if isinstance(issue, Failure):
|
||||
return issue
|
||||
if not isinstance(issue.scores, dict) or issue.scores.get(FILED_BY[0]) != FILED_BY[1]:
|
||||
continue
|
||||
scored = scores(issue.key, issue.scores)
|
||||
if isinstance(scored, Failure):
|
||||
return scored
|
||||
levels, moves, exempt = scored
|
||||
if exempt == SECURITY:
|
||||
continue
|
||||
if new.exempt == SECURITY:
|
||||
return issue.key
|
||||
if missing := next((name for name in SET_SCORES if name not in levels), None):
|
||||
return Failure(f"{issue.key} holds no {missing}")
|
||||
# Release, tagline and blockers don't change a score.
|
||||
other = ranking.item_score(dataclasses.replace(new, id=issue.number, exempt=exempt, scores=levels, moves=moves), scoring, issue.key)
|
||||
if isinstance(other, Failure) or other < value:
|
||||
return other if isinstance(other, Failure) else issue.key
|
||||
return None
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
|
||||
+33
-12
@@ -13,7 +13,7 @@ from failure import Failure
|
||||
from git_cli.git_repo import file_at, git, Git
|
||||
from record_store.stores import goals_store, store as record_store, RecordStore
|
||||
from plan_store import markdown_edits
|
||||
from project_config.settings import ProjectConfig
|
||||
from project_config.settings import ProjectConfig, Scoring
|
||||
from release_plan import ranking
|
||||
from release_plan.release import Release
|
||||
from text_files.file_writes import replace_file
|
||||
@@ -139,16 +139,36 @@ class FilePlan:
|
||||
plan = read_text(self.path, MISSING)
|
||||
if isinstance(plan, Failure):
|
||||
return plan
|
||||
goals = self.goals.read()
|
||||
if isinstance(goals, Failure):
|
||||
return goals
|
||||
if not goals:
|
||||
return Failure(f"{self.goals.label}: missing or empty; {GOALS_HINT}")
|
||||
decisions = self.decisions.read()
|
||||
if isinstance(decisions, Failure):
|
||||
return decisions
|
||||
history = self.history.read()
|
||||
return history if isinstance(history, Failure) else (plan, goals, decisions, history)
|
||||
weighing = weighing_texts(self.goals, self.decisions, self.history)
|
||||
return weighing if isinstance(weighing, Failure) else (plan, *weighing)
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class StatedScoring:
|
||||
"""The scoring that the project's config states for a plan in Jira, whose goal weights ranking reads from the goals file, the decision log and the comprehension history."""
|
||||
stated: Scoring
|
||||
goals: RecordStore
|
||||
decisions: RecordStore
|
||||
history: RecordStore
|
||||
floor: decimal.Decimal
|
||||
|
||||
def read(self) -> ranking.Scoring | Failure:
|
||||
weighing = weighing_texts(self.goals, self.decisions, self.history)
|
||||
return weighing if isinstance(weighing, Failure) else ranking.config_scoring(self.stated.formula, self.stated.bar, *weighing, self.floor)
|
||||
|
||||
|
||||
def weighing_texts(goals: RecordStore, decisions: RecordStore, history: RecordStore) -> tuple[str, str, str] | Failure:
|
||||
"""What ranking weighs the goals by: the goals file, the decision log and the comprehension history. The last two are empty when missing; a goals file that is missing or empty is a Failure."""
|
||||
goals_text = goals.read()
|
||||
if isinstance(goals_text, Failure):
|
||||
return goals_text
|
||||
if not goals_text:
|
||||
return Failure(f"{goals.label}: missing or empty; {GOALS_HINT}")
|
||||
decisions_text = decisions.read()
|
||||
if isinstance(decisions_text, Failure):
|
||||
return decisions_text
|
||||
history_text = history.read()
|
||||
return history_text if isinstance(history_text, Failure) else (goals_text, decisions_text, history_text)
|
||||
|
||||
|
||||
def store(config: ProjectConfig) -> PlanStore:
|
||||
@@ -159,7 +179,8 @@ def store(config: ProjectConfig) -> PlanStore:
|
||||
from plan_store.jira_epic import JiraPlan
|
||||
# load refuses a config that names an epic and no env-file.
|
||||
assert config.env_file is not None
|
||||
return JiraPlan(config.epic, config.env_file, finish_by=config.jira_finish)
|
||||
scoring = StatedScoring(config.jira_scoring, goals_store(config), record_store(config, "decisions"), record_store(config, "comprehension-history"), config.readability_floor) if config.jira_scoring else None
|
||||
return JiraPlan(config.epic, config.env_file, finish_by=config.jira_finish, scoring=scoring)
|
||||
|
||||
|
||||
def file_plan(config: ProjectConfig, path: pathlib.Path | None = None) -> FilePlan:
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import base64
|
||||
import dataclasses
|
||||
import pathlib
|
||||
import sys
|
||||
import tempfile
|
||||
@@ -7,11 +8,12 @@ import unittest.mock
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from project_config.settings import Epic, Finish
|
||||
from project_config.settings import DEFAULT_FLOOR, Epic, Finish
|
||||
from release_plan.todo_table import EXEMPTIONS
|
||||
from failure import Failure
|
||||
from plan_store import jira_epic
|
||||
from plan_store.stores import Plan, Written
|
||||
from release_plan import ranking
|
||||
from adf_codec.convert import Refused
|
||||
from release_plan.release import release_of
|
||||
|
||||
@@ -220,6 +222,24 @@ VERSIONS = "https://acme.atlassian.net/rest/api/3/project/ABC/versions"
|
||||
PERHAPS_FILED = "unless Jira refused the request, the issue may exist: look under ABC-12 before filing the item again"
|
||||
FIELDS = {"Release": "0.1.0", "Tagline": "Count the runs.", "L": "1", "E": "2", "I": "3", "S": "1", "Moves": "1 by 9"}
|
||||
PROPERTY = {"L": 1, "E": 2, "I": 3, "S": 1, "Moves": "1 by 9", "Exempt": "", "Filed by": "loop"}
|
||||
RANK = "https://acme.atlassian.net/rest/agile/1.0/issue/rank"
|
||||
# Goal 1 weighs 1 and goal 2, a maintain goal, 0.5, so under the formula V / 2**S, FIELDS scores 9 / 2 = 4.5.
|
||||
README = "# P\n\n## Goals\n\n**Void:** code health, since a test project has no code to read.\n\n1. **Achieve:** Fast.\n2. **Maintain:** Correct.\n\n## Audience\n\nMe.\n"
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Stated:
|
||||
"""Stands in for the scoring a project's config states, with the goal weights README gives."""
|
||||
formula: str = "V / 2**S"
|
||||
bar: float = 1
|
||||
|
||||
def read(self) -> ranking.Scoring | Failure:
|
||||
return ranking.config_scoring(self.formula, self.bar, README, "", "", DEFAULT_FLOOR)
|
||||
|
||||
|
||||
def filed(key: str, moves: str = "1 by 9", s: int = 1, exempt: str = "") -> dict[str, object]:
|
||||
"""An open child the loop filed, which scores 9 / 2**s with moves "1 by 9"."""
|
||||
return issue(key, scores=PROPERTY | {"Moves": moves, "S": s, "Exempt": exempt})
|
||||
|
||||
|
||||
class Filing(unittest.TestCase):
|
||||
@@ -232,25 +252,27 @@ class Filing(unittest.TestCase):
|
||||
self.created: object = {"id": "10040", "key": "ABC-40"}
|
||||
self.linked: object = None
|
||||
self.versions: object = [{"name": "0.1.0"}, {"name": "v0.2.0"}, "odd", {"name": ["0.1.0"]}, {"name": {"en": "0.1.0"}}]
|
||||
self.ranked: object = None
|
||||
self.scoring: Stated | None = Stated()
|
||||
|
||||
def http(self, method: str, url: str, authorization: str, body: object) -> object:
|
||||
"""Stands in for Jira: answers the epic, self.versions for the project's Fix Versions, self.open to the search, self.created to a new issue and self.linked to a new link."""
|
||||
self.calls.append((method, url, body))
|
||||
assert authorization == AUTHORIZATION
|
||||
return {SEARCH: {"issues": self.open}, ISSUES: self.created, LINKS: self.linked, VERSIONS: self.versions}.get(url, {"key": "ABC-12"})
|
||||
return {SEARCH: {"issues": self.open}, ISSUES: self.created, LINKS: self.linked, VERSIONS: self.versions, RANK: self.ranked}.get(url, {"key": "ABC-12"})
|
||||
|
||||
def to_adf(self, markdown: str) -> dict[str, object] | Failure:
|
||||
return adf(markdown)
|
||||
|
||||
def add(self, fields: dict[str, str] = FIELDS, detail: str = ""):
|
||||
return jira_epic.JiraPlan(EPIC, self.env, self.http, text_of, self.to_adf).add(fields, detail)
|
||||
return jira_epic.JiraPlan(EPIC, self.env, self.http, text_of, self.to_adf, scoring=self.scoring).add(fields, detail)
|
||||
|
||||
def sent(self, url: str) -> list[object]:
|
||||
return [body for _, sent_to, body in self.calls if sent_to == url]
|
||||
|
||||
def test_files_the_item_as_a_task_under_the_epic_marked_as_the_loops(self):
|
||||
self.assertEqual(self.add(), Written(40))
|
||||
self.assertEqual(self.calls, [("GET", VERSIONS, None), ("POST", ISSUES, {
|
||||
self.assertEqual([call for call in self.calls if call[1] != SEARCH and "/issue/ABC-12" not in call[1]], [("GET", VERSIONS, None), ("POST", ISSUES, {
|
||||
"fields": {"project": {"key": "ABC"}, "parent": {"key": "ABC-12"}, "issuetype": {"name": "Task"}, "summary": "Count the runs.", "fixVersions": [{"name": "0.1.0"}]},
|
||||
"properties": [{"key": "plan-item", "value": PROPERTY}],
|
||||
})])
|
||||
@@ -303,6 +325,7 @@ class Filing(unittest.TestCase):
|
||||
self.assertEqual(self.add({name: value for name, value in FIELDS.items() if name != "Tagline"}), Failure("the item has no tagline"))
|
||||
|
||||
def test_an_item_without_moves_files_with_none(self):
|
||||
self.scoring = Stated(bar=0)
|
||||
self.assertEqual(self.add({name: value for name, value in FIELDS.items() if name != "Moves"}), Written(40))
|
||||
self.assertEqual(self.sent(ISSUES)[0]["properties"][0]["value"]["Moves"], "") # type: ignore[index]
|
||||
|
||||
@@ -367,6 +390,63 @@ class Filing(unittest.TestCase):
|
||||
self.assertIsInstance(self.add(), Failure)
|
||||
self.assertEqual(self.calls, [])
|
||||
|
||||
def test_an_item_under_the_bar_fails_before_any_request(self):
|
||||
self.assertEqual(self.add(FIELDS | {"Moves": "2 by 1", "S": "3"}), Failure("the item to file scores 0.1, under the bar 1; don't file it, or mark it with a reason the bar doesn't apply"))
|
||||
self.assertEqual(self.calls, [])
|
||||
|
||||
def test_an_exempt_item_under_the_bar_files(self):
|
||||
self.assertEqual(self.add(FIELDS | {"Moves": "", "Exempt": "owner"}), Written(40))
|
||||
|
||||
def test_an_item_that_names_a_goal_the_goals_file_lacks_fails_before_any_request(self):
|
||||
self.assertEqual(self.add(FIELDS | {"Moves": "3 by 1"}), Failure("the item to file cites goal 3, which the goals file's ## Goals does not number"))
|
||||
self.assertEqual(self.calls, [])
|
||||
|
||||
def test_an_item_without_every_score_fails_before_any_request(self):
|
||||
self.assertEqual(self.add({name: value for name, value in FIELDS.items() if name != "S"}), Failure("the item to file has no S: score it on L, E, I and S"))
|
||||
self.assertEqual(self.calls, [])
|
||||
|
||||
def test_a_formula_that_does_not_parse_fails_before_any_request(self):
|
||||
self.scoring = Stated(formula="V +")
|
||||
self.assertEqual(self.add(), Failure("cannot score the item to file: the formula 'V +' does not parse"))
|
||||
self.assertEqual(self.calls, [])
|
||||
|
||||
def test_a_config_without_a_formula_fails(self):
|
||||
self.scoring = None
|
||||
self.assertEqual(self.add(), Failure("the config states no formula and bar to score the item by: set `jira-score-formula` and `jira-score-bar`, as `project-config --help` shows"))
|
||||
|
||||
def test_ranks_the_item_just_before_the_first_issue_the_loop_filed_that_scores_lower(self):
|
||||
# ABC-30 and ABC-33 are a person's, ABC-31 a security finding, and ABC-32 scores as much as the new item.
|
||||
self.open = [issue("ABC-30"), filed("ABC-31", s=4, exempt="security"), filed("ABC-32"), issue("ABC-33", scores={"L": 1, "E": 1, "I": 1, "S": 4, "Moves": "1 by 1"}), filed("ABC-34", s=2), filed("ABC-35", s=3)]
|
||||
self.assertEqual(self.add(), Written(40))
|
||||
self.assertEqual(self.sent(RANK), [{"issues": ["ABC-40"], "rankBeforeIssue": "ABC-34"}])
|
||||
self.assertEqual([method for method, url, _ in self.calls if url == RANK], ["PUT"])
|
||||
|
||||
def test_ranks_a_security_finding_just_before_the_first_issue_the_loop_filed_that_isnt_one(self):
|
||||
self.open = [issue("ABC-30"), filed("ABC-31", exempt="security"), filed("ABC-32"), filed("ABC-33", s=4)]
|
||||
self.assertEqual(self.add(FIELDS | {"Exempt": "security", "S": "4"}), Written(40))
|
||||
self.assertEqual(self.sent(RANK), [{"issues": ["ABC-40"], "rankBeforeIssue": "ABC-32"}])
|
||||
|
||||
def test_leaves_the_item_last_where_no_issue_the_loop_filed_scores_lower(self):
|
||||
self.open = [issue("ABC-30", scores={}), filed("ABC-31"), filed("ABC-32", s=2, exempt="security")]
|
||||
self.assertEqual(self.add(), Written(40))
|
||||
self.assertEqual(self.sent(RANK), [])
|
||||
|
||||
def test_a_rank_jira_refuses_leaves_the_item_filed_with_a_note(self):
|
||||
self.open = [filed("ABC-34", s=2)]
|
||||
refusals = (
|
||||
(Failure("PUT /rest/agile/1.0/issue/rank answered 403: Forbidden"), "PUT /rest/agile/1.0/issue/rank answered 403: Forbidden"),
|
||||
({"entries": [{"issueKey": "ABC-40", "status": 400, "errors": ["Rank is not configured"]}]}, "Rank is not configured"),
|
||||
)
|
||||
for answer, reason in refusals:
|
||||
with self.subTest(answer=answer):
|
||||
self.ranked = answer
|
||||
self.assertEqual(self.add(), Written(40, (f"filed ABC-40, but cannot rank it before ABC-34: {reason}; rank it in Jira",)))
|
||||
|
||||
def test_an_issue_the_loop_filed_that_does_not_score_leaves_the_item_filed_unranked_with_a_note(self):
|
||||
self.open = [filed("ABC-34", moves="3 by 1", s=2)]
|
||||
self.assertEqual(self.add(), Written(40, ("filed ABC-40, but cannot rank it: ABC-34 cites goal 3, which the goals file's ## Goals does not number; rank it in Jira",)))
|
||||
self.assertEqual(self.sent(RANK), [])
|
||||
|
||||
|
||||
TRANSITIONS = "https://acme.atlassian.net/rest/api/3/issue/ABC-34/transitions"
|
||||
|
||||
|
||||
@@ -8,9 +8,9 @@ import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from project_config.settings import DEFAULT_FLOOR, Epic, Finish, ProjectConfig, SETTINGS
|
||||
from project_config.settings import DEFAULT_FLOOR, Epic, Finish, ProjectConfig, Scoring, SETTINGS
|
||||
from failure import Failure
|
||||
from record_store.stores import FileStore
|
||||
from record_store.stores import FileStore, goals_store, store as record_store
|
||||
from plan_store.contract import FIRST, MOVES, PlanStoreContract, SECOND
|
||||
from plan_store.jira_epic import JiraPlan
|
||||
from plan_store.fakes import MemoryPlan
|
||||
@@ -215,6 +215,25 @@ class Store(unittest.TestCase):
|
||||
picked = stores.store(self.config(epic=Epic("https://acme.atlassian.net", "ABC-12"), env_file=pathlib.Path("/secrets/acme.env"), jira_finish=finish))
|
||||
self.assertEqual(picked.finish_by, finish)
|
||||
|
||||
def test_an_epic_scores_by_the_configs_formula_and_bar_and_the_projects_records(self):
|
||||
config = self.config(epic=Epic("https://acme.atlassian.net", "ABC-12"), env_file=pathlib.Path("/secrets/acme.env"), jira_scoring=Scoring("V / 2**S", 1.5), readability_floor=decimal.Decimal("6.5"))
|
||||
picked = stores.store(config)
|
||||
self.assertEqual(picked.scoring, stores.StatedScoring(Scoring("V / 2**S", 1.5), goals_store(config), record_store(config, "decisions"), record_store(config, "comprehension-history"), decimal.Decimal("6.5")))
|
||||
|
||||
|
||||
class StatedScoring(unittest.TestCase):
|
||||
def test_weighs_the_goals_the_goals_file_holds(self):
|
||||
scoring = stores.StatedScoring(Scoring("V / 2**S", 1.5), MemoryStore(README), MemoryStore(), MemoryStore(), DEFAULT_FLOOR).read()
|
||||
assert not isinstance(scoring, Failure), scoring
|
||||
self.assertEqual((scoring.bar, list(scoring.goals)), (1.5, ["1", "2", "2.1"]))
|
||||
|
||||
def test_a_goals_file_that_is_empty_or_cannot_be_read_fails(self):
|
||||
for goals, reason in ((MemoryStore(), "the record in memory: missing or empty"), (MemoryStore(fails="Jira answered 403"), "Jira answered 403")):
|
||||
with self.subTest(reason=reason):
|
||||
read = stores.StatedScoring(Scoring("V", 1), goals, MemoryStore(), MemoryStore(), DEFAULT_FLOOR).read()
|
||||
assert isinstance(read, Failure), read
|
||||
self.assertTrue(read.reason.startswith(reason), read.reason)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user