Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 19 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ Usage of junit2jira:
-orchestrator string
Orchestrator name (such as GKE or OpenShift), if any.
-priority-thresholds string
Comma-separated minimum comment counts for priority escalation (Minor,Normal,Major,Critical,Blocker). (default "2,10,50,100,200")
Comma-separated minimum comment counts for priority escalation (Minor,Normal,Major,Critical,Blocker). (default "1,2,12,24,48")
-priority-window-days int
Number of recent days used for automatic priority escalation. (default 30)
Number of recent days used for automatic priority escalation. (default 7)
-slack-output string
Generate JSON output in slack format (use dash [-] for stdout)
-threshold int
Expand All @@ -71,9 +71,9 @@ Usage of junit2jira:

Automatic priority escalation is disabled by default. With `--enable-auto-priority`,
`junit2jira` evaluates an existing issue after successfully adding a comment to it.
It counts comments in one recent activity window, which defaults to 30 days and
can be changed with `--priority-window-days`. Newly created issues are not evaluated
for escalation during that run.
It counts comments in one recent activity window, which is controlled by
`--priority-window-days` option. Newly created issues are not evaluated for
escalation during that run.

All available comment pages are fetched before counting. Comments from any author
count if their creation timestamp is strictly after the window's start; comments
Expand All @@ -85,35 +85,33 @@ The default thresholds map the comment count in that window to a target priority

| Window count | Priority |
|-------------|----------|
| 0-1 | Undefined |
| 2-9 | Minor |
| 10-49 | Normal |
| 50-99 | Major |
| 100-199 | Critical |
| 200+ | Blocker |

Priority is only
raised: for example, an issue with 12 recent comments moves from Minor to Normal,
but an issue already at Blocker stays at Blocker. Unrecognized Jira priority names
are left unchanged with a warning.
| 0 | Undefined |
| 1 | Minor |
| 2-11 | Normal |
| 12-23 | Major |
| 24-47 | Critical |
| 48+ | Blocker |

Priority is only raised. For example, a Minor issue that got enough recent comments
moves from Minor to Normal, but an issue already at Blocker stays at Blocker.
Unrecognized Jira priority names are left unchanged with a warning.

`--priority-window-days` must be a positive integer. `--priority-thresholds` must
contain exactly five comma-separated, non-negative integers in strictly ascending
order. These are minimum comment counts for Minor, Normal, Major, Critical, and
Blocker, respectively. For example, 12 comments in the selected window yields
Normal with the defaults, but Minor with `10,50,100,200,400`. Invalid configuration
is rejected at startup, even when automatic escalation is disabled.
Blocker, respectively. Invalid configuration is rejected at startup, even when
automatic escalation is disabled.

With `--dry-run`, no comment is added and automatic priority evaluation is skipped;
the command does not preview the resulting priority.

For example, to count comments from the last 10 days and use thresholds of
For example, to count comments from the last 30 days and use thresholds of
10, 50, 100, 200, and 400:

```shell
junit2jira \
--enable-auto-priority \
--priority-window-days 10 \
--priority-window-days 30 \
--priority-thresholds "10,50,100,200,400" \
...
```
Expand Down
2 changes: 1 addition & 1 deletion cmd/junit2jira/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func main() {
flag.StringVar(&p.Orchestrator, "orchestrator", "", "Orchestrator name (such as GKE or OpenShift), if any.")
flag.BoolVar(&p.enableAutoPriority, "enable-auto-priority", false, "Enable automatic priority escalation based on comment count.")
flag.StringVar(&p.priorityThresholds, "priority-thresholds", priorityThresholdsString(defaultPriorityThresholds), "Comma-separated minimum comment counts for priority escalation (Minor,Normal,Major,Critical,Blocker).")
flag.IntVar(&p.priorityWindowDays, "priority-window-days", 30, "Number of recent days used for automatic priority escalation.")
flag.IntVar(&p.priorityWindowDays, "priority-window-days", 7, "Number of recent days used for automatic priority escalation.")
flag.BoolVar(&debug, "debug", false, "Enable debug log level")
versioninfo.AddFlag(flag.CommandLine)
flag.Parse()
Expand Down
2 changes: 1 addition & 1 deletion cmd/junit2jira/priority.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func parsePriority(name string) (Priority, bool) {
// defaultPriorityThresholds are minimum comment counts within the configured
// activity window for Minor, Normal, Major, Critical, and Blocker, respectively.
// Keep the defaults and count ranges in README.md in sync when changing these.
var defaultPriorityThresholds = []int{2, 10, 50, 100, 200}
var defaultPriorityThresholds = []int{1, 2, 12, 24, 48}

func priorityThresholdsString(thresholds []int) string {
values := make([]string, len(thresholds))
Expand Down
40 changes: 24 additions & 16 deletions cmd/junit2jira/priority_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"testing"
"time"

Expand All @@ -24,26 +25,33 @@ func TestPriorityForCommentCount(t *testing.T) {
func TestPriorityForCommentCountCustomThresholds(t *testing.T) {
customThresholds, err := parsePriorityThresholds("10,50,100,200,400")
require.NoError(t, err)
for name, test := range map[string]struct {
count int
for count, test := range map[int]struct {
defaultPriority Priority
customPriority Priority
}{
"below Minor": {9, Minor, Undefined},
"Minor boundary": {10, Normal, Minor},
"same count different priority": {12, Normal, Minor},
"below Normal": {49, Normal, Minor},
"Normal boundary": {50, Major, Normal},
"below Major": {99, Major, Normal},
"Major boundary": {100, Critical, Major},
"below Critical": {199, Critical, Major},
"Critical boundary": {200, Blocker, Critical},
"below Blocker": {399, Blocker, Critical},
"Blocker boundary": {400, Blocker, Blocker},
0: {Undefined, Undefined},
1: {Minor, Undefined},
2: {Normal, Undefined},
11: {Normal, Minor},
12: {Major, Minor},
23: {Major, Minor},
24: {Critical, Minor},
47: {Critical, Minor},
49: {Blocker, Minor},
50: {Blocker, Normal},
99: {Blocker, Normal},
100: {Blocker, Major},
199: {Blocker, Major},
200: {Blocker, Critical},
399: {Blocker, Critical},
400: {Blocker, Blocker},
} {
t.Run(name, func(t *testing.T) {
require.Equal(t, test.defaultPriority, priorityForCommentCount(test.count, defaultPriorityThresholds))
require.Equal(t, test.customPriority, priorityForCommentCount(test.count, customThresholds))
t.Run(fmt.Sprintf("count=%d", count), func(t *testing.T) {
defaultRes := priorityForCommentCount(count, defaultPriorityThresholds)
require.Equal(t, test.defaultPriority, defaultRes, "priority for default thresholds does not match")

customRes := priorityForCommentCount(count, customThresholds)
require.Equal(t, test.customPriority, customRes, "priority for custom thresholds does not match")
})
}
}
Expand Down