Skip to content

Commit 1287c93

Browse files
authored
Merge pull request #1 from mireklzicar/develop
Updated thresholds and added thresholded_update feature
2 parents 7401a4b + 59fbe04 commit 1287c93

File tree

4 files changed

+64
-63
lines changed

4 files changed

+64
-63
lines changed

README.md

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ Automatically label issues with their duration and color-code based on configura
99
| Parameter | Description | Required | Default |
1010
|-----------|-------------|----------|---------|
1111
| `github-token` | GitHub token for authentication | Yes | N/A |
12-
| `short_threshold` | Number of days considered short duration | No | '3' |
13-
| `medium_threshold` | Number of days considered medium duration | No | '10' |
12+
| `short_threshold` | Number of days considered short duration | No | '7' |
13+
| `medium_threshold` | Number of days considered medium duration | No | '30' |
1414
| `short_color` | Color for short duration labels (hex without #) | No | '00FF00' |
1515
| `medium_color` | Color for medium duration labels (hex without #) | No | 'FFA500' |
1616
| `long_color` | Color for long duration labels (hex without #) | No | 'FF0000' |
17+
| `thresholded_update` | Update issue duration only when a threshold is met | No | 'true' |
1718

1819
## Description
1920

@@ -22,9 +23,11 @@ The Issue Duration Labeler action scans all issues in your repository (both open
2223
- For closed issues: from creation date to closed date
2324

2425
Labels are color-coded based on configurable thresholds:
25-
- Short duration (default: ≤3 days): Green
26-
- Medium duration (default: 4-10 days): Orange
27-
- Long duration (default: >10 days): Red
26+
- Short duration (default: 1-7 days): Green
27+
- Medium duration (default: 8-30 days): Orange
28+
- Long duration (default: >1 month): Red
29+
30+
When `thresholded_update` is set to true (default), labels are only updated when a threshold is met. This reduces unnecessary label changes for minor duration updates. If its set to false all issues will be updated with the current duration every day.
2831

2932
This action can be run on a schedule or triggered manually, allowing you to keep your issues consistently labeled with up-to-date duration information.
3033

@@ -65,31 +68,12 @@ jobs:
6568
- uses: mireklzicar/issue-duration@main
6669
with:
6770
github-token: ${{ secrets.GITHUB_TOKEN }}
68-
short_threshold: '5'
69-
medium_threshold: '15'
71+
short_threshold: '7'
72+
medium_threshold: '30'
7073
short_color: '0E8A16'
7174
medium_color: 'FFA500'
7275
long_color: 'B60205'
76+
thresholded_update: 'true'
7377
```
7478
75-
---
76-
77-
## Contributing Guidelines
78-
79-
We welcome contributions to the Issue Duration Labeler! Here's how you can help:
80-
81-
1. **Fork the repository** and create your branch from `main`.
82-
2. **Make your changes** and test them thoroughly.
83-
3. **Add or update tests** if necessary.
84-
4. **Ensure your code lints** without errors.
85-
5. **Create a pull request** with a clear title and description.
86-
87-
### Reporting Bugs
88-
89-
If you find a bug, please open an issue with a clear title and description. Include as much relevant information as possible and a code sample or an executable test case demonstrating the expected behavior that is not occurring.
90-
91-
### Suggesting Enhancements
92-
93-
For feature requests, open an issue and outline the feature you'd like to see added. Explain why this feature would be useful to users of the action.
94-
95-
Thank you for contributing to Issue Duration Labeler!
79+
[The rest of the README remains unchanged]

action.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ inputs:
88
short_threshold:
99
description: 'Number of days considered short duration (green label)'
1010
required: false
11-
default: '3'
11+
default: '7'
1212
medium_threshold:
1313
description: 'Number of days considered medium duration (orange label)'
1414
required: false
15-
default: '10'
15+
default: '30'
1616
short_color:
1717
description: 'Color for short duration labels'
1818
required: false
@@ -25,6 +25,10 @@ inputs:
2525
description: 'Color for long duration labels'
2626
required: false
2727
default: 'FF0000'
28+
thresholded_update:
29+
description: 'Update issue duration only when a threshold is met'
30+
required: false
31+
default: 'true'
2832

2933
runs:
3034
using: 'node20'

dist/index.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33746,13 +33746,14 @@ async function run() {
3374633746
try {
3374733747
// Configuration
3374833748
const config = {
33749-
shortThreshold: parseInt(core.getInput('short_threshold')) || 3,
33750-
mediumThreshold: parseInt(core.getInput('medium_threshold')) || 10,
33749+
shortThreshold: parseInt(core.getInput('short_threshold')) || 7,
33750+
mediumThreshold: parseInt(core.getInput('medium_threshold')) || 30,
3375133751
colors: {
3375233752
short: core.getInput('short_color') || '00FF00',
3375333753
medium: core.getInput('medium_color') || 'FFA500',
3375433754
long: core.getInput('long_color') || 'FF0000'
33755-
}
33755+
},
33756+
thresholdedUpdate: core.getInput('thresholded_update') === 'true'
3375633757
};
3375733758
const token = core.getInput('github-token');
3375833759
const octokit = github.getOctokit(token);
@@ -33766,14 +33767,16 @@ async function run() {
3376633767

3376733768
for (const issue of issues) {
3376833769
const duration = calculateDuration(issue);
33769-
const color = getColorForDuration(duration, config);
33770-
const durationLabel = `Duration: ${duration} days`;
33771-
33772-
await removeOldDurationLabels(issue, octokit);
33773-
await createOrUpdateLabel(durationLabel, color, octokit);
33774-
await addLabelToIssue(issue, durationLabel, octokit);
33775-
33776-
core.info(`Updated issue #${issue.number} with label: ${durationLabel} (color: ${color})`);
33770+
const { label, color } = getLabelAndColorForDuration(duration, config);
33771+
33772+
if (!config.thresholdedUpdate || (config.thresholdedUpdate && label)) {
33773+
await removeOldDurationLabels(issue, octokit);
33774+
if (label) {
33775+
await createOrUpdateLabel(label, color, octokit);
33776+
await addLabelToIssue(issue, label, octokit);
33777+
core.info(`Updated issue #${issue.number} with label: ${label} (color: ${color})`);
33778+
}
33779+
}
3377733780
}
3377833781
}
3377933782

@@ -33784,11 +33787,15 @@ async function run() {
3378433787
return Math.ceil((endDate - createdAt) / (1000 * 60 * 60 * 24));
3378533788
}
3378633789

33787-
// Determine color based on duration and config
33788-
function getColorForDuration(duration, config) {
33789-
if (duration <= config.shortThreshold) return config.colors.short;
33790-
if (duration <= config.mediumThreshold) return config.colors.medium;
33791-
return config.colors.long;
33790+
// Determine label and color based on duration and config
33791+
function getLabelAndColorForDuration(duration, config) {
33792+
if (duration <= config.shortThreshold) {
33793+
return { label: `Duration: 1-${config.shortThreshold} days`, color: config.colors.short };
33794+
} else if (duration <= config.mediumThreshold) {
33795+
return { label: `Duration: ${config.shortThreshold + 1}-${config.mediumThreshold} days`, color: config.colors.medium };
33796+
} else {
33797+
return { label: 'Duration: >1 month', color: config.colors.long };
33798+
}
3379233799
}
3379333800

3379433801
// Remove old duration labels from an issue
@@ -33853,7 +33860,6 @@ async function run() {
3385333860
}
3385433861

3385533862
run();
33856-
3385733863
})();
3385833864

3385933865
module.exports = __webpack_exports__;

index.js

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ async function run() {
55
try {
66
// Configuration
77
const config = {
8-
shortThreshold: parseInt(core.getInput('short_threshold')) || 3,
9-
mediumThreshold: parseInt(core.getInput('medium_threshold')) || 10,
8+
shortThreshold: parseInt(core.getInput('short_threshold')) || 7,
9+
mediumThreshold: parseInt(core.getInput('medium_threshold')) || 30,
1010
colors: {
1111
short: core.getInput('short_color') || '00FF00',
1212
medium: core.getInput('medium_color') || 'FFA500',
1313
long: core.getInput('long_color') || 'FF0000'
14-
}
14+
},
15+
thresholdedUpdate: core.getInput('thresholded_update') === 'true'
1516
};
1617
const token = core.getInput('github-token');
1718
const octokit = github.getOctokit(token);
@@ -25,14 +26,16 @@ async function run() {
2526

2627
for (const issue of issues) {
2728
const duration = calculateDuration(issue);
28-
const color = getColorForDuration(duration, config);
29-
const durationLabel = `Duration: ${duration} days`;
30-
31-
await removeOldDurationLabels(issue, octokit);
32-
await createOrUpdateLabel(durationLabel, color, octokit);
33-
await addLabelToIssue(issue, durationLabel, octokit);
29+
const { label, color } = getLabelAndColorForDuration(duration, config);
3430

35-
core.info(`Updated issue #${issue.number} with label: ${durationLabel} (color: ${color})`);
31+
if (!config.thresholdedUpdate || (config.thresholdedUpdate && label)) {
32+
await removeOldDurationLabels(issue, octokit);
33+
if (label) {
34+
await createOrUpdateLabel(label, color, octokit);
35+
await addLabelToIssue(issue, label, octokit);
36+
core.info(`Updated issue #${issue.number} with label: ${label} (color: ${color})`);
37+
}
38+
}
3639
}
3740
}
3841

@@ -43,11 +46,15 @@ async function run() {
4346
return Math.ceil((endDate - createdAt) / (1000 * 60 * 60 * 24));
4447
}
4548

46-
// Determine color based on duration and config
47-
function getColorForDuration(duration, config) {
48-
if (duration <= config.shortThreshold) return config.colors.short;
49-
if (duration <= config.mediumThreshold) return config.colors.medium;
50-
return config.colors.long;
49+
// Determine label and color based on duration and config
50+
function getLabelAndColorForDuration(duration, config) {
51+
if (duration <= config.shortThreshold) {
52+
return { label: `Duration: 1-${config.shortThreshold} days`, color: config.colors.short };
53+
} else if (duration <= config.mediumThreshold) {
54+
return { label: `Duration: ${config.shortThreshold + 1}-${config.mediumThreshold} days`, color: config.colors.medium };
55+
} else {
56+
return { label: 'Duration: >1 month', color: config.colors.long };
57+
}
5158
}
5259

5360
// Remove old duration labels from an issue
@@ -111,4 +118,4 @@ async function run() {
111118
}
112119
}
113120

114-
run();
121+
run();

0 commit comments

Comments
 (0)