Skip to content

Commit

Permalink
Merge pull request #1 from mireklzicar/develop
Browse files Browse the repository at this point in the history
Updated thresholds and added thresholded_update feature
  • Loading branch information
mireklzicar authored Sep 1, 2024
2 parents 7401a4b + 59fbe04 commit 1287c93
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 63 deletions.
40 changes: 12 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ Automatically label issues with their duration and color-code based on configura
| Parameter | Description | Required | Default |
|-----------|-------------|----------|---------|
| `github-token` | GitHub token for authentication | Yes | N/A |
| `short_threshold` | Number of days considered short duration | No | '3' |
| `medium_threshold` | Number of days considered medium duration | No | '10' |
| `short_threshold` | Number of days considered short duration | No | '7' |
| `medium_threshold` | Number of days considered medium duration | No | '30' |
| `short_color` | Color for short duration labels (hex without #) | No | '00FF00' |
| `medium_color` | Color for medium duration labels (hex without #) | No | 'FFA500' |
| `long_color` | Color for long duration labels (hex without #) | No | 'FF0000' |
| `thresholded_update` | Update issue duration only when a threshold is met | No | 'true' |

## Description

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

Labels are color-coded based on configurable thresholds:
- Short duration (default: ≤3 days): Green
- Medium duration (default: 4-10 days): Orange
- Long duration (default: >10 days): Red
- Short duration (default: 1-7 days): Green
- Medium duration (default: 8-30 days): Orange
- Long duration (default: >1 month): Red

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.

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.

Expand Down Expand Up @@ -65,31 +68,12 @@ jobs:
- uses: mireklzicar/issue-duration@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
short_threshold: '5'
medium_threshold: '15'
short_threshold: '7'
medium_threshold: '30'
short_color: '0E8A16'
medium_color: 'FFA500'
long_color: 'B60205'
thresholded_update: 'true'
```
---
## Contributing Guidelines
We welcome contributions to the Issue Duration Labeler! Here's how you can help:
1. **Fork the repository** and create your branch from `main`.
2. **Make your changes** and test them thoroughly.
3. **Add or update tests** if necessary.
4. **Ensure your code lints** without errors.
5. **Create a pull request** with a clear title and description.

### Reporting Bugs

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.

### Suggesting Enhancements

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.

Thank you for contributing to Issue Duration Labeler!
[The rest of the README remains unchanged]
8 changes: 6 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ inputs:
short_threshold:
description: 'Number of days considered short duration (green label)'
required: false
default: '3'
default: '7'
medium_threshold:
description: 'Number of days considered medium duration (orange label)'
required: false
default: '10'
default: '30'
short_color:
description: 'Color for short duration labels'
required: false
Expand All @@ -25,6 +25,10 @@ inputs:
description: 'Color for long duration labels'
required: false
default: 'FF0000'
thresholded_update:
description: 'Update issue duration only when a threshold is met'
required: false
default: 'true'

runs:
using: 'node20'
Expand Down
40 changes: 23 additions & 17 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33746,13 +33746,14 @@ async function run() {
try {
// Configuration
const config = {
shortThreshold: parseInt(core.getInput('short_threshold')) || 3,
mediumThreshold: parseInt(core.getInput('medium_threshold')) || 10,
shortThreshold: parseInt(core.getInput('short_threshold')) || 7,
mediumThreshold: parseInt(core.getInput('medium_threshold')) || 30,
colors: {
short: core.getInput('short_color') || '00FF00',
medium: core.getInput('medium_color') || 'FFA500',
long: core.getInput('long_color') || 'FF0000'
}
},
thresholdedUpdate: core.getInput('thresholded_update') === 'true'
};
const token = core.getInput('github-token');
const octokit = github.getOctokit(token);
Expand All @@ -33766,14 +33767,16 @@ async function run() {

for (const issue of issues) {
const duration = calculateDuration(issue);
const color = getColorForDuration(duration, config);
const durationLabel = `Duration: ${duration} days`;

await removeOldDurationLabels(issue, octokit);
await createOrUpdateLabel(durationLabel, color, octokit);
await addLabelToIssue(issue, durationLabel, octokit);

core.info(`Updated issue #${issue.number} with label: ${durationLabel} (color: ${color})`);
const { label, color } = getLabelAndColorForDuration(duration, config);

if (!config.thresholdedUpdate || (config.thresholdedUpdate && label)) {
await removeOldDurationLabels(issue, octokit);
if (label) {
await createOrUpdateLabel(label, color, octokit);
await addLabelToIssue(issue, label, octokit);
core.info(`Updated issue #${issue.number} with label: ${label} (color: ${color})`);
}
}
}
}

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

// Determine color based on duration and config
function getColorForDuration(duration, config) {
if (duration <= config.shortThreshold) return config.colors.short;
if (duration <= config.mediumThreshold) return config.colors.medium;
return config.colors.long;
// Determine label and color based on duration and config
function getLabelAndColorForDuration(duration, config) {
if (duration <= config.shortThreshold) {
return { label: `Duration: 1-${config.shortThreshold} days`, color: config.colors.short };
} else if (duration <= config.mediumThreshold) {
return { label: `Duration: ${config.shortThreshold + 1}-${config.mediumThreshold} days`, color: config.colors.medium };
} else {
return { label: 'Duration: >1 month', color: config.colors.long };
}
}

// Remove old duration labels from an issue
Expand Down Expand Up @@ -33853,7 +33860,6 @@ async function run() {
}

run();

})();

module.exports = __webpack_exports__;
Expand Down
39 changes: 23 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ async function run() {
try {
// Configuration
const config = {
shortThreshold: parseInt(core.getInput('short_threshold')) || 3,
mediumThreshold: parseInt(core.getInput('medium_threshold')) || 10,
shortThreshold: parseInt(core.getInput('short_threshold')) || 7,
mediumThreshold: parseInt(core.getInput('medium_threshold')) || 30,
colors: {
short: core.getInput('short_color') || '00FF00',
medium: core.getInput('medium_color') || 'FFA500',
long: core.getInput('long_color') || 'FF0000'
}
},
thresholdedUpdate: core.getInput('thresholded_update') === 'true'
};
const token = core.getInput('github-token');
const octokit = github.getOctokit(token);
Expand All @@ -25,14 +26,16 @@ async function run() {

for (const issue of issues) {
const duration = calculateDuration(issue);
const color = getColorForDuration(duration, config);
const durationLabel = `Duration: ${duration} days`;

await removeOldDurationLabels(issue, octokit);
await createOrUpdateLabel(durationLabel, color, octokit);
await addLabelToIssue(issue, durationLabel, octokit);
const { label, color } = getLabelAndColorForDuration(duration, config);

core.info(`Updated issue #${issue.number} with label: ${durationLabel} (color: ${color})`);
if (!config.thresholdedUpdate || (config.thresholdedUpdate && label)) {
await removeOldDurationLabels(issue, octokit);
if (label) {
await createOrUpdateLabel(label, color, octokit);
await addLabelToIssue(issue, label, octokit);
core.info(`Updated issue #${issue.number} with label: ${label} (color: ${color})`);
}
}
}
}

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

// Determine color based on duration and config
function getColorForDuration(duration, config) {
if (duration <= config.shortThreshold) return config.colors.short;
if (duration <= config.mediumThreshold) return config.colors.medium;
return config.colors.long;
// Determine label and color based on duration and config
function getLabelAndColorForDuration(duration, config) {
if (duration <= config.shortThreshold) {
return { label: `Duration: 1-${config.shortThreshold} days`, color: config.colors.short };
} else if (duration <= config.mediumThreshold) {
return { label: `Duration: ${config.shortThreshold + 1}-${config.mediumThreshold} days`, color: config.colors.medium };
} else {
return { label: 'Duration: >1 month', color: config.colors.long };
}
}

// Remove old duration labels from an issue
Expand Down Expand Up @@ -111,4 +118,4 @@ async function run() {
}
}

run();
run();

0 comments on commit 1287c93

Please sign in to comment.