diff --git a/.github/workflows/set-version-labels-test.yml b/.github/workflows/set-version-labels-test.yml index abb6389..90b2226 100644 --- a/.github/workflows/set-version-labels-test.yml +++ b/.github/workflows/set-version-labels-test.yml @@ -17,3 +17,4 @@ jobs: uses: camunda/automation-platform-github-actions/version-label-automation-manual@Version-Labels-Automation with: issue: ${{ github.event.inputs.issue }} + repo-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/common/dist/index.js b/common/dist/index.js index b2aa245..dbcade0 100644 --- a/common/dist/index.js +++ b/common/dist/index.js @@ -163772,81 +163772,82 @@ module.exports = SBOMParser; const core = __nccwpck_require__(42186); const github = __nccwpck_require__(95438); -const octokit = __nccwpck_require__(72785)(); module.exports = async function () { - const repo = github.context.payload.repository; - const owner = repo.owner.login; - const issueNumber = core.getInput('issue'); + const replacePrefix = function (strings, oldPrefix, newPrefix) { + return strings.map(str => { + if (str.startsWith(oldPrefix)) { + return newPrefix + str.slice(oldPrefix.length); + } + return str; + }); + } - const potentialLabels = await getLabelsWithPrefix(owner, repo, issueNumber, `potential`); - const versionLabels = replacePrefix(potentialLabels, "potential", "version"); + const removeLabels = async function (owner, repo, issueNumber, labels) { + console.log(`Remove labels for issue #${issueNumber}:`, labels); + try { + for (const label of labels) { + await octokit.issues.removeLabel({ + owner, + repo, + issue_number: issueNumber, + name: label // Use the current label in the iteration + }); + console.log(`Label "${label}" removed from issue #${issueNumber}`); + } + } catch (error) { + console.error('Error removing labels:', error); + } + } - await removeLabels(owner, repo, issueNumber, potentialLabels); - await setLabels(owner, repo, issueNumber, versionLabels); -} + const getLabelsWithPrefix = async function (owner, repo, issueNumber, prefix) { + console.log(`Get labels with prefix for issue: #${issueNumber}`); + try { + // Get issue details, which includes labels + const { data: issue } = await octokit.issues.get({ + owner, + repo, + issue_number: issueNumber, + }); + + // Filter labels that start with the specified prefix + const matchingLabels = issue.labels + .map(label => label.name) + .filter(label => label.startsWith(prefix)); -const replacePrefix = function(strings, oldPrefix, newPrefix) { - return strings.map(str => { - if (str.startsWith(oldPrefix)) { - return newPrefix + str.slice(oldPrefix.length); + console.log(`Labels starting with "${prefix}":`, matchingLabels); + return matchingLabels; + } catch (error) { + console.error('Error fetching issue labels:', error); } - return str; - }); -} + } -const removeLabels = async function (owner, repo, issueNumber, labels) { - console.log(`Remove labels for issue #${issueNumber}:`, labels); - try { - for (const label of labels) { - await octokit.issues.removeLabel({ + const setLabels = async function (owner, repo, issueNumber, labels) { + console.log(`Set labels for issue: #${issueNumber}:`, labels); + try { + await octokit.issues.addLabels({ owner, repo, issue_number: issueNumber, - name: label // Use the current label in the iteration + labels: labels }); - console.log(`Label "${label}" removed from issue #${issueNumber}`); + console.log(`Labels set to issue #${issueNumber}:`, labels); + } catch (error) { + console.error('Error setting labels:', error); } - } catch (error) { - console.error('Error removing labels:', error); } -} - -const getLabelsWithPrefix = async function (owner, repo, issueNumber, prefix) { - console.log(`Get labels with prefix for issue: #${issueNumber}`); - try { - // Get issue details, which includes labels - const { data: issue } = await octokit.issues.get({ - owner, - repo, - issue_number: issueNumber, - }); - // Filter labels that start with the specified prefix - const matchingLabels = issue.labels - .map(label => label.name) - .filter(label => label.startsWith(prefix)); + const repoToken = core.getInput('repo-token'); + const octokit = github.getOctokit(repoToken); + const repo = github.context.payload.repository; + const owner = repo.owner.login; + const issueNumber = core.getInput('issue-number'); - console.log(`Labels starting with "${prefix}":`, matchingLabels); - return matchingLabels; - } catch (error) { - console.error('Error fetching issue labels:', error); - } -} + const potentialLabels = await getLabelsWithPrefix(owner, repo, issueNumber, `potential`); + const versionLabels = replacePrefix(potentialLabels, "potential", "version"); -const setLabels = async function (owner, repo, issueNumber, labels) { - console.log(`Set labels for issue: #${issueNumber}:`, labels); - try { - await octokit.issues.addLabels({ - owner, - repo, - issue_number: issueNumber, - labels: labels - }); - console.log(`Labels set to issue #${issueNumber}:`, labels); - } catch (error) { - console.error('Error setting labels:', error); - } + await removeLabels(owner, repo, issueNumber, potentialLabels); + await setLabels(owner, repo, issueNumber, versionLabels); } /***/ }), @@ -164022,14 +164023,6 @@ exports.formatLinkList = function(links, prefix) { } -/***/ }), - -/***/ 72785: -/***/ ((module) => { - -module.exports = eval("require")("@octokit/rest"); - - /***/ }), /***/ 71269: diff --git a/common/src/set-version-labels.js b/common/src/set-version-labels.js index bf1c943..66e5d77 100644 --- a/common/src/set-version-labels.js +++ b/common/src/set-version-labels.js @@ -1,78 +1,79 @@ const core = require('@actions/core'); const github = require('@actions/github'); -const octokit = require("@octokit/rest")(); module.exports = async function () { - const repo = github.context.payload.repository; - const owner = repo.owner.login; - const issueNumber = core.getInput('issue'); + const replacePrefix = function (strings, oldPrefix, newPrefix) { + return strings.map(str => { + if (str.startsWith(oldPrefix)) { + return newPrefix + str.slice(oldPrefix.length); + } + return str; + }); + } - const potentialLabels = await getLabelsWithPrefix(owner, repo, issueNumber, `potential`); - const versionLabels = replacePrefix(potentialLabels, "potential", "version"); + const removeLabels = async function (owner, repo, issueNumber, labels) { + console.log(`Remove labels for issue #${issueNumber}:`, labels); + try { + for (const label of labels) { + await octokit.issues.removeLabel({ + owner, + repo, + issue_number: issueNumber, + name: label // Use the current label in the iteration + }); + console.log(`Label "${label}" removed from issue #${issueNumber}`); + } + } catch (error) { + console.error('Error removing labels:', error); + } + } - await removeLabels(owner, repo, issueNumber, potentialLabels); - await setLabels(owner, repo, issueNumber, versionLabels); -} + const getLabelsWithPrefix = async function (owner, repo, issueNumber, prefix) { + console.log(`Get labels with prefix for issue: #${issueNumber}`); + try { + // Get issue details, which includes labels + const { data: issue } = await octokit.issues.get({ + owner, + repo, + issue_number: issueNumber, + }); -const replacePrefix = function(strings, oldPrefix, newPrefix) { - return strings.map(str => { - if (str.startsWith(oldPrefix)) { - return newPrefix + str.slice(oldPrefix.length); + // Filter labels that start with the specified prefix + const matchingLabels = issue.labels + .map(label => label.name) + .filter(label => label.startsWith(prefix)); + + console.log(`Labels starting with "${prefix}":`, matchingLabels); + return matchingLabels; + } catch (error) { + console.error('Error fetching issue labels:', error); } - return str; - }); -} + } -const removeLabels = async function (owner, repo, issueNumber, labels) { - console.log(`Remove labels for issue #${issueNumber}:`, labels); - try { - for (const label of labels) { - await octokit.issues.removeLabel({ + const setLabels = async function (owner, repo, issueNumber, labels) { + console.log(`Set labels for issue: #${issueNumber}:`, labels); + try { + await octokit.issues.addLabels({ owner, repo, issue_number: issueNumber, - name: label // Use the current label in the iteration + labels: labels }); - console.log(`Label "${label}" removed from issue #${issueNumber}`); + console.log(`Labels set to issue #${issueNumber}:`, labels); + } catch (error) { + console.error('Error setting labels:', error); } - } catch (error) { - console.error('Error removing labels:', error); } -} - -const getLabelsWithPrefix = async function (owner, repo, issueNumber, prefix) { - console.log(`Get labels with prefix for issue: #${issueNumber}`); - try { - // Get issue details, which includes labels - const { data: issue } = await octokit.issues.get({ - owner, - repo, - issue_number: issueNumber, - }); - // Filter labels that start with the specified prefix - const matchingLabels = issue.labels - .map(label => label.name) - .filter(label => label.startsWith(prefix)); + const repoToken = core.getInput('repo-token'); + const octokit = github.getOctokit(repoToken); + const repo = github.context.payload.repository; + const owner = repo.owner.login; + const issueNumber = core.getInput('issue-number'); - console.log(`Labels starting with "${prefix}":`, matchingLabels); - return matchingLabels; - } catch (error) { - console.error('Error fetching issue labels:', error); - } -} + const potentialLabels = await getLabelsWithPrefix(owner, repo, issueNumber, `potential`); + const versionLabels = replacePrefix(potentialLabels, "potential", "version"); -const setLabels = async function (owner, repo, issueNumber, labels) { - console.log(`Set labels for issue: #${issueNumber}:`, labels); - try { - await octokit.issues.addLabels({ - owner, - repo, - issue_number: issueNumber, - labels: labels - }); - console.log(`Labels set to issue #${issueNumber}:`, labels); - } catch (error) { - console.error('Error setting labels:', error); - } + await removeLabels(owner, repo, issueNumber, potentialLabels); + await setLabels(owner, repo, issueNumber, versionLabels); } \ No newline at end of file