Skip to content

Commit

Permalink
use oktokit form actions/github
Browse files Browse the repository at this point in the history
  • Loading branch information
venetrius committed Oct 10, 2024
1 parent e54bb78 commit 8cf6b3c
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 126 deletions.
1 change: 1 addition & 0 deletions .github/workflows/set-version-labels-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
127 changes: 60 additions & 67 deletions common/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/***/ }),
Expand Down Expand Up @@ -164022,14 +164023,6 @@ exports.formatLinkList = function(links, prefix) {
}


/***/ }),

/***/ 72785:
/***/ ((module) => {

module.exports = eval("require")("@octokit/rest");


/***/ }),

/***/ 71269:
Expand Down
119 changes: 60 additions & 59 deletions common/src/set-version-labels.js
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 8cf6b3c

Please sign in to comment.