Merge pull request #98 from laurentenhoor/fix/97-clean-label-transitions

fix: ensure clean label transitions by removing all state labels
This commit is contained in:
Lauren ten Hoor
2026-02-10 18:00:19 +08:00
committed by GitHub
2 changed files with 62 additions and 8 deletions

View File

@@ -151,11 +151,38 @@ export class GitHubProvider implements TaskManager {
from: StateLabel, from: StateLabel,
to: StateLabel, to: StateLabel,
): Promise<void> { ): Promise<void> {
await this.gh([ // Fetch current issue to get all labels
const issue = await this.getIssue(issueId);
// Find all state labels currently on the issue
const currentStateLabels = issue.labels.filter((label) =>
STATE_LABELS.includes(label as StateLabel),
);
// If no state labels to remove, just add the new one
if (currentStateLabels.length === 0) {
await this.gh([
"issue", "edit", String(issueId),
"--add-label", to,
]);
return;
}
// Remove all state labels and add the new one in a single operation
// This ensures clean transitions: "removed X, added Y" instead of messy multi-label operations
const args = [
"issue", "edit", String(issueId), "issue", "edit", String(issueId),
"--remove-label", from, ];
"--add-label", to,
]); // Add all current state labels to remove
for (const label of currentStateLabels) {
args.push("--remove-label", label);
}
// Add the new state label
args.push("--add-label", to);
await this.gh(args);
} }
async closeIssue(issueId: number): Promise<void> { async closeIssue(issueId: number): Promise<void> {

View File

@@ -116,11 +116,38 @@ export class GitLabProvider implements TaskManager {
from: StateLabel, from: StateLabel,
to: StateLabel, to: StateLabel,
): Promise<void> { ): Promise<void> {
await this.glab([ // Fetch current issue to get all labels
const issue = await this.getIssue(issueId);
// Find all state labels currently on the issue
const currentStateLabels = issue.labels.filter((label) =>
STATE_LABELS.includes(label as StateLabel),
);
// If no state labels to remove, just add the new one
if (currentStateLabels.length === 0) {
await this.glab([
"issue", "update", String(issueId),
"--label", to,
]);
return;
}
// Remove all state labels and add the new one in a single operation
// This ensures clean transitions: "removed X, added Y" instead of messy multi-label operations
const args = [
"issue", "update", String(issueId), "issue", "update", String(issueId),
"--unlabel", from, ];
"--label", to,
]); // Add all current state labels to remove
for (const label of currentStateLabels) {
args.push("--unlabel", label);
}
// Add the new state label
args.push("--label", to);
await this.glab(args);
} }
async closeIssue(issueId: number): Promise<void> { async closeIssue(issueId: number): Promise<void> {