Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

4.7 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
6a1d9f98e819ed70a0e994df Challenge 333: Issue Triage 2 29 challenge-333

--description--

Given an issue title and an array of current labels, return an updated array of labels based on the following rules:

If the issue doesn't have any labels, add:

  • "bug" and "needs triage" if the title contains "error" or "bug"
  • "enhancement" and "discussing" if the title contains "feature" or "add"

Otherwise, if the given labels contain:

  • "needs triage" and the title contains "simple" or "easy", remove "needs triage" and add "good first issue"
  • "discussing" and the title contains "planned" or "next", remove "discussing" and add "on the roadmap"
  • Otherwise, if "needs triage" or "discussing" is present, remove it and add "help wanted"

If the title contains:

  • "security", add a "critical" label

--hints--

triage_issue("app crashes with error", []) should return ["bug", "needs triage"].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(sorted(triage_issue("app crashes with error", [])), sorted(["bug", "needs triage"]))`)
}})

triage_issue("app crashes with error", ["bug", "needs triage"]) should return ["bug", "help wanted"].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(sorted(triage_issue("app crashes with error", ["bug", "needs triage"])), sorted(["bug", "help wanted"]))`)
}})

triage_issue("add dark mode", []) should return ["enhancement", "discussing"].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(sorted(triage_issue("add dark mode", [])), sorted(["enhancement", "discussing"]))`)
}})

triage_issue("add dark mode", ["enhancement", "discussing"]) should return ["enhancement", "help wanted"].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(sorted(triage_issue("add dark mode", ["enhancement", "discussing"])), sorted(["enhancement", "help wanted"]))`)
}})

triage_issue("xss security bug", []) should return ["bug", "needs triage", "critical"].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(sorted(triage_issue("xss security bug", [])), sorted(["bug", "needs triage", "critical"]))`)
}})

triage_issue("security vulnerability in auth", []) should return ["critical"].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(sorted(triage_issue("security vulnerability in auth", [])), sorted(["critical"]))`)
}})

triage_issue("easy a11y fix", ["bug", "needs triage"]) should return ["bug", "good first issue"].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(sorted(triage_issue("easy a11y fix", ["bug", "needs triage"])), sorted(["bug", "good first issue"]))`)
}})

triage_issue("planned api migration", ["enhancement", "discussing"]) should return ["enhancement", "on the roadmap"].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(sorted(triage_issue("planned api migration", ["enhancement", "discussing"])), sorted(["enhancement", "on the roadmap"]))`)
}})

triage_issue("improve security", ["enhancement", "discussing"]) should return ["enhancement", "help wanted", "critical"].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(sorted(triage_issue("improve security", ["enhancement", "discussing"])), sorted(["enhancement", "help wanted", "critical"]))`)
}})

--seed--

--seed-contents--

def triage_issue(title, labels):

    return title

--solutions--

def triage_issue(title, labels):
    result = list(labels)
    t = title.lower()

    def has(label):
        return label in result

    def add(label):
        if not has(label):
            result.append(label)

    def remove(label):
        if label in result:
            result.remove(label)

    if len(result) == 0:
        if "error" in t or "bug" in t:
            add("bug")
            add("needs triage")
        elif "feature" in t or "add" in t:
            add("enhancement")
            add("discussing")
    else:
        if has("needs triage") and ("simple" in t or "easy" in t):
            remove("needs triage")
            add("good first issue")
        elif has("discussing") and ("planned" in t or "next" in t):
            remove("discussing")
            add("on the roadmap")
        elif has("needs triage") or has("discussing"):
            remove("needs triage")
            remove("discussing")
            add("help wanted")

    if "security" in t:
        add("critical")

    return result