Skip to content

Commit

Permalink
Enable usage of different exit code when queries not satisfied
Browse files Browse the repository at this point in the history
Only return exit code 0 if all queries are good, return exit code 3 if
any query is not OK.

Reference: https://progress.opensuse.org/issues/137828
  • Loading branch information
baierjan committed Jan 5, 2024
1 parent 5f08511 commit 1229106
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Additional arguments affecting the behavior of the script:

`--reminder-comment-on-issues` can be added here to enable automatic reminder comments. This is **not** enabled by default because it's designed to be used in scheduled runs. Manual execution and previews of changed queries are not expected to have side-effects.

`--exit-code` can be added to also emit return code 3 if any of the configured queries is not within its limit.

## folder

The output folder for the generated HTML. By default this is `gh-pages`.
Expand Down
11 changes: 9 additions & 2 deletions backlogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def check_backlog(conf):


def render_table(data):
all_good = True
rows = []
for conf in data["queries"]:
good, issue_count = check_backlog(conf)
Expand All @@ -132,7 +133,9 @@ def render_table(data):
result_icons["pass"] if good else result_icons["fail"],
]
)
return rows
if not good:
all_good = False
return (all_good, rows)


def cycle_time(issue, status_ids):
Expand Down Expand Up @@ -220,6 +223,7 @@ def render_influxdb(data):
"--output", choices=["markdown", "influxdb"], default="markdown"
)
parser.add_argument("--reminder-comment-on-issues", action="store_false")
parser.add_argument("--exit-code", action="store_true")
switches = parser.parse_args()
try:
with open(switches.config, "r") as config:
Expand All @@ -230,7 +234,10 @@ def render_influxdb(data):
else:
initialize_md(data)
with open("index.md", "a") as md:
for row in render_table(data):
all_good, rows = render_table(data)
for row in rows:
md.write("|".join(row) + "\n")
except FileNotFoundError:
sys.exit("Configuration file {} not found".format(switches.config))
if switches.exit_code and not all_good:
sys.exit(3)
2 changes: 1 addition & 1 deletion tests/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def test_markdown(self):
]
)
self.assertEqual(
backlogger.render_table(backlogger.data),
backlogger.render_table(backlogger.data)[1],
[
[
"[Workable Backlog](https://example.com/issues?query_id=123)",
Expand Down

0 comments on commit 1229106

Please sign in to comment.