Skip to content

Commit b990f00

Browse files
committed
Shell/Daily: Interleave Attention vs. CI reports
1 parent b8126fd commit b990f00

File tree

12 files changed

+173
-88
lines changed

12 files changed

+173
-88
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- GitHub/Actions: Permitted commandeering the time interval per `--when` option
1515
- GitHub/Actions: Added filtering duplicates
1616
- GitHub/Activity: Added section about "Top issues"
17+
- Shell/Daily: Interleaved Attention vs. CI reports
1718

1819
## v0.3.0, 2025-02-24
1920
- Opsgenie: Added alert reporter. Thanks, @WalBah.

docs/backlog.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# Backlog
22

33
## Iteration +1
4-
- Shell/Daily: Interleave CI reports
5-
- Aika: Fix bugs and refactor code
6-
- Pueblo: Fix bugs and refactor code
4+
- `rapporto report` without `--github-repository` should iterate **all** repositories
5+
- Bugfixing and refactoring: Aika and Pueblo
76

87
## Iteration +2
98
- Options: Program currently understands `--slack-token=`, but lacks `--github-token=`
@@ -84,3 +83,4 @@
8483
- UI/Slack: Improve zapping
8584
- GitHub/Actions: Currently lacks parameter `--when`
8685
- GitHub/Activity: Section about "Top issues"
86+
- Shell/Daily: Interleave CI reports

docs/report/index.md

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,34 +40,44 @@ export SLACK_TOKEN="xoxb-your-slack-bot-token"
4040
Alternatively to using the environment variable, you can also use the
4141
`rapporto notify --slack-token=` command-line option.
4242

43-
### Options
44-
45-
The [`--when`](#when-option) command-line option accepts a wide range of
46-
values to adjust the time interval. You can also omit the option completely,
47-
in which case the program will assume the current day or calendar week.
48-
4943
## Markdown Reports
5044

51-
Report about given day.
45+
Report attention items about a given day.
5246
```shell
53-
rapporto report --github-organization="acme" daily --when="2025-02-28"
47+
rapporto report --github-organization="acme" daily --day="2025-02-28"
5448
```
5549

5650
Report about given calendar week.
5751
```shell
58-
rapporto report --github-organization="acme" weekly --when="2025W09"
52+
rapporto report --github-organization="acme" weekly --day="2025W09"
5953
```
6054

6155
Print yesterday's report.
6256
```shell
63-
rapporto report --github-organization="acme" daily --when="yesterday"
57+
rapporto report --github-organization="acme" daily --day="yesterday"
6458
```
6559

6660
Print today's report in YAML format.
6761
```shell
6862
rapporto report --github-organization="acme" --format="yaml" daily
6963
```
7064

65+
Report attention items and CI failures about a given day.
66+
```shell
67+
rapporto report \
68+
--github-organization="acme" \
69+
--github-repository="acme/foobar" \
70+
daily --day="2025-02-28"
71+
```
72+
73+
Load list of repositories from file.
74+
```shell
75+
rapporto report \
76+
--github-organization="acme" \
77+
--github-repository="/path/to/repositories.txt" \
78+
daily --day="2025-02-28"
79+
```
80+
7181

7282
## Slack Conversations
7383

@@ -81,6 +91,14 @@ Report and notify about given calendar week.
8191
rapporto notify --gh-org="acme" --slack-channel="janitor-bot" weekly --week="2025W09"
8292
```
8393

94+
Report and notify about given calendar week, loading list of repositories from file.
95+
```shell
96+
rapporto notify \
97+
--gh-org="acme" --gh-repo="/path/to/repositories.txt" \
98+
--slack-channel="janitor-bot" \
99+
weekly --week="2025W09"
100+
```
101+
84102
For development purposes, zap messages after pressing enter.
85103
```shell
86104
rapporto notify --gh-org="acme" --slack-channel="janitor-bot" weekly --zap=key

src/rapporto/notify/cli.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,39 @@
55
from pueblo_goof.slack.conversation import SlackConversation
66
from pueblo_goof.slack.model import SlackOptions, slack_api_token_option, slack_channel_option
77
from pueblo_goof.util import Zapper
8-
from rapporto.option import github_organization_option
8+
from rapporto.option import github_organization_option, github_repository_option
99
from rapporto.report.model import ReportOptions
1010
from rapporto.report.slack import SlackWeekly
11+
from rapporto.source.github.model import GitHubOptions
1112

1213
logger = logging.getLogger(__name__)
1314

1415

1516
@click.group()
1617
@github_organization_option
18+
@github_repository_option
1719
@slack_api_token_option
1820
@slack_channel_option
1921
@click.pass_context
20-
def cli(ctx: click.Context, github_organization: str, slack_token: str, slack_channel: str):
22+
def cli(
23+
ctx: click.Context,
24+
github_organization: str,
25+
github_repository: str,
26+
slack_token: str,
27+
slack_channel: str,
28+
):
2129
"""
2230
Notify humans and machines.
2331
"""
2432
if not slack_token:
2533
raise click.UsageError(
2634
"Missing option '--slack-token' or environment variable 'SLACK_TOKEN'."
2735
)
28-
ctx.meta["slack_options"] = SlackOptions(token=slack_token, channel=slack_channel)
29-
ctx.meta["report_options"] = ReportOptions(
30-
github_organization=github_organization, output_format="markdown"
36+
ctx.meta["github_options"] = GitHubOptions(organization=github_organization).add_repos(
37+
github_repository
3138
)
39+
ctx.meta["slack_options"] = SlackOptions(token=slack_token, channel=slack_channel)
40+
ctx.meta["report_options"] = ReportOptions(output_format="markdown")
3241

3342

3443
@cli.command()
@@ -40,13 +49,19 @@ def weekly(ctx: click.Context, week: str, zap: str):
4049
Weekly report converged into Slack thread.
4150
"""
4251

52+
github_options: GitHubOptions = ctx.meta["github_options"]
4353
report_options: ReportOptions = ctx.meta["report_options"]
4454
slack_options: SlackOptions = ctx.meta["slack_options"]
4555

4656
conversation = SlackConversation(options=slack_options)
4757
zapper = Zapper(when=zap, action=conversation.delete)
4858

49-
section = SlackWeekly(week=week, options=report_options, conversation=conversation)
59+
section = SlackWeekly(
60+
week=week,
61+
github_options=github_options,
62+
report_options=report_options,
63+
conversation=conversation,
64+
)
5065
section.refresh()
5166

5267
try:

src/rapporto/option.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
import click
22

33
github_organization_option = click.option(
4-
"--github-organization", "--gh-org", type=str, required=True
4+
"--github-organization", "--gh-org", type=str, required=True, help="GitHub organization name"
55
)
6+
github_repository_option = click.option(
7+
"--github-repository",
8+
"--gh-repo",
9+
type=str,
10+
required=True,
11+
help="GitHub repository, single or path to file",
12+
)
13+
format_option = click.option(
14+
"--format",
15+
"format_",
16+
type=str,
17+
required=False,
18+
default="markdown",
19+
help="Output format. Default: markdown",
20+
)
21+
when_option = click.option("--when", type=str, required=False, help="Point in time")

src/rapporto/report/cli.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,60 @@
22

33
import click
44

5-
from rapporto.option import github_organization_option
5+
from rapporto.option import (
6+
format_option,
7+
github_organization_option,
8+
github_repository_option,
9+
)
610
from rapporto.report.model import DailyReport, ReportOptions, WeeklyReport
11+
from rapporto.source.github.model import GitHubOptions
712

813
logger = logging.getLogger(__name__)
914

10-
format_option = click.option("--format", "format_", type=str, required=True, default="markdown")
11-
1215

1316
@click.group()
1417
@github_organization_option
18+
@github_repository_option
1519
@format_option
1620
@click.pass_context
17-
def cli(ctx: click.Context, github_organization: str, format_: str):
21+
def cli(ctx: click.Context, github_organization: str, github_repository: str, format_: str):
1822
"""
1923
Generate reports.
2024
"""
21-
ctx.meta["options"] = ReportOptions(
22-
github_organization=github_organization, output_format=format_
25+
ctx.meta["github_options"] = GitHubOptions(organization=github_organization).add_repos(
26+
github_repository
2327
)
28+
ctx.meta["report_options"] = ReportOptions(output_format=format_)
2429

2530

2631
@cli.command()
27-
@click.option("--when", type=str, required=False, help="Point in time")
32+
@click.option("--day", type=str, required=False, help="Day in ISO format, e.g. 2025-03-03")
2833
@click.pass_context
29-
def daily(ctx: click.Context, when: str):
34+
def daily(ctx: click.Context, day: str):
3035
"""
3136
Daily report.
3237
"""
3338
report = DailyReport(
34-
day=when,
35-
options=ctx.meta["options"],
39+
day=day,
40+
github_options=ctx.meta["github_options"],
41+
report_options=ctx.meta["report_options"],
3642
)
3743
report.process()
38-
print(report.render(report.options.output_format))
44+
print(report.render(report.report_options.output_format))
3945

4046

4147
@cli.command()
42-
@click.option("--when", type=str, required=False, help="Point in time")
48+
@click.option("--week", type=str, required=False, help="Calendar week in ISO format, e.g. 2025W03")
49+
@github_repository_option
4350
@click.pass_context
44-
def weekly(ctx: click.Context, when: str):
51+
def weekly(ctx: click.Context, week: str):
4552
"""
4653
Weekly report.
4754
"""
4855
report = WeeklyReport(
49-
week=when,
50-
options=ctx.meta["options"],
56+
week=week,
57+
github_options=ctx.meta["github_options"],
58+
report_options=ctx.meta["report_options"],
5159
)
5260
report.process()
53-
print(report.render(report.options.output_format))
61+
print(report.render(report.report_options.output_format))

src/rapporto/report/model.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
import yaml
77
from attrs import define
88

9+
from rapporto.source.github.actions import GitHubActionsReport
910
from rapporto.source.github.attention import GitHubAttentionReport
10-
from rapporto.source.github.model import GitHubInquiry
11+
from rapporto.source.github.model import GitHubInquiry, GitHubMultiRepositoryInquiry, GitHubOptions
1112
from rapporto.util import week_to_day_range
1213

1314

@@ -39,7 +40,6 @@ class ReportOptions:
3940
Composite report options.
4041
"""
4142

42-
github_organization: str
4343
output_format: str = "markdown"
4444

4545

@@ -92,7 +92,8 @@ class DailyReport(ReportBase):
9292
"""
9393

9494
day: str
95-
options: ReportOptions
95+
github_options: GitHubOptions
96+
report_options: ReportOptions
9697
items: t.List[DailyItem] = attr.field(factory=list)
9798

9899
def __attrs_post_init__(self):
@@ -106,14 +107,28 @@ def process(self):
106107
"""
107108
Generate set of reports across different domains or topics.
108109
"""
110+
self.github_actions()
109111
self.github_attention()
110112

113+
def github_actions(self):
114+
"""
115+
CI workflow run failures on GitHub.
116+
"""
117+
# TODO: Use `TimeIntervalParser`.
118+
created = f"{self.day}..{self.day}"
119+
inquiry = GitHubMultiRepositoryInquiry(
120+
repositories=self.github_options.repositories, created=created
121+
)
122+
report = GitHubActionsReport(inquiry=inquiry)
123+
self.items.append(DailyItem(type="github-actions", day=self.day, markdown=report.markdown))
124+
111125
def github_attention(self):
112126
"""
113127
Items on GitHub that deserve your attention.
114128
"""
129+
# TODO: Use `TimeIntervalParser`.
115130
updated = f"{self.day}..{self.day}"
116-
inquiry = GitHubInquiry(organization=self.options.github_organization, updated=updated)
131+
inquiry = GitHubInquiry(organization=self.github_options.organization, updated=updated)
117132
report = GitHubAttentionReport(inquiry=inquiry)
118133
self.items.append(
119134
DailyItem(type="github-attention", day=self.day, markdown=report.markdown)
@@ -133,7 +148,8 @@ class WeeklyReport(ReportBase):
133148
"""
134149

135150
week: str
136-
options: ReportOptions
151+
github_options: GitHubOptions
152+
report_options: ReportOptions
137153
dailies: t.List[DailyReport] = attr.field(factory=list)
138154

139155
SKIP_THE_FUTURE = True
@@ -159,7 +175,9 @@ def process(self):
159175
Create all daily reports.
160176
"""
161177
for day in self.days:
162-
report = DailyReport(day=day, options=self.options)
178+
report = DailyReport(
179+
day=day, github_options=self.github_options, report_options=self.report_options
180+
)
163181
report.process()
164182
self.dailies.append(report)
165183

src/rapporto/report/slack.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from pueblo_goof.slack.conversation import SlackConversation
1111
from rapporto.report.model import DailyItem, ReportOptions, WeeklyReport
12+
from rapporto.source.github.model import GitHubOptions
1213

1314
logger = logging.getLogger(__name__)
1415

@@ -24,7 +25,8 @@ class SlackWeekly:
2425
AUTHOR = "qa-bot"
2526

2627
week: str
27-
options: ReportOptions
28+
github_options: GitHubOptions
29+
report_options: ReportOptions
2830
conversation: SlackConversation
2931

3032
# Message id of the root message.
@@ -87,7 +89,8 @@ def root_markdown(self):
8789
def render(self):
8890
weekly = WeeklyReport(
8991
week=self.week,
90-
options=self.options,
92+
github_options=self.github_options,
93+
report_options=self.report_options,
9194
)
9295
weekly.process()
9396
for daily_report in weekly.dailies:

0 commit comments

Comments
 (0)