Skip to content

Commit

Permalink
ci(.github/action): change the label-and-move-released-issues action …
Browse files Browse the repository at this point in the history
…to work with the issue owner and the issue repo (#183)

* ci(.github/action): change the label-and-move-released-issues action to work with the issue owner and the issue repo

* ci(.github/action): change the label name and the logic how to work with labels of issue repos in the label-and-move-released-issues action

* ci(.github/action): change unit-tests of the label-and-move-released-issues action
  • Loading branch information
maksym-shynkarenko authored Jul 2, 2024
1 parent f540f30 commit ac46c03
Show file tree
Hide file tree
Showing 6 changed files with 411 additions and 91 deletions.
83 changes: 52 additions & 31 deletions .github/actions/label-and-move-released-issues-v1/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30569,6 +30569,14 @@ async function getReferencedClosedIssues({ owner, repo, pullRequestID, octokit }
nodes {
# The issue number of the issue that was closed
number
repository {
# The owner where an issue was created
owner {
login
}
# The repo name where an issue was created
name
}
}
}
}
Expand Down Expand Up @@ -30667,22 +30675,10 @@ async function run(core, github) {
core.setFailed(`\nColumn ${releaseColumn} not found in project board ${projectNumber}`);
return;
}
const labels = await octokit.rest.issues.listLabelsForRepo({
repo,
owner
});
core.info(`Found ${labels.data.length} labels`);
const LABEL = `VERSION: ${version}`;
const hasLabel = labels.data.some(label => label.name === LABEL);
if (!hasLabel) {
core.info(`Label "${LABEL}" does not exist, creating...`);
await octokit.rest.issues.createLabel({
repo,
owner,
name: LABEL,
color: 'FFFFFF'
});
}
const LABEL = `VERSION: ${repo}@${version}`;
let issueOwner;
let issueRepo;
let issueNumber;
const issueURLs = [];
const commits = JSON.parse(commitList);
core.info(`Found ${commits.length} commits`);
Expand All @@ -30697,21 +30693,31 @@ async function run(core, github) {
pullRequestID: parseInt(id),
octokit
});
const issueIDs = referenceClosedIssues.repository.pullRequest.closingIssuesReferences.nodes.map(n => n.number);
if (!issueIDs.length) {
const issueDataArr = referenceClosedIssues.repository.pullRequest.closingIssuesReferences.nodes.reduce((arr, item) => {
arr.push({
number: item.number,
owner: item.repository.owner.login,
repo: item.repository.name
});
return arr;
}, []);
if (!issueDataArr.length) {
core.info('\nNo issues found for commit, moving on...');
continue;
}
for (const issueNumber of issueIDs) {
core.info(`\nFetching project board info for: ${owner}, ${repo}, issue: ${issueNumber} for project: ${projectNumber}`);
const issueStatus = await (0, getIssueProjectInfo_1.default)({
owner,
repo,
for (const issueData of issueDataArr) {
issueOwner = issueData.owner;
issueRepo = issueData.repo;
issueNumber = issueData.number;
core.info(`\nFetching project board info for: ${owner}/${repo}, PR: ${id}, issue: ${issueNumber} for project: ${projectNumber}`);
const issueStats = await (0, getIssueProjectInfo_1.default)({
owner: issueOwner,
repo: issueRepo,
issueNumber,
octokit
});
core.info(`Found stats: ${JSON.stringify(issueStatus)}`);
const projectBoard = issueStatus.repository.issue.projectItems.nodes.find(n => n.project.number === projectNumber);
core.info(`Found stats: ${JSON.stringify(issueStats)}`);
const projectBoard = issueStats.repository.issue.projectItems.nodes.find(n => n.project.number === projectNumber);
if (!projectBoard) {
core.info(`\nCould not find the project board "${projectNumber}" for issue ${issueNumber}, moving on...`);
continue;
Expand All @@ -30722,21 +30728,36 @@ async function run(core, github) {
continue;
}
const { data: issue } = await octokit.rest.issues.get({
repo,
owner,
repo: issueRepo,
owner: issueOwner,
issue_number: issueNumber
});
if (issue.state !== 'closed') {
await octokit.rest.issues.update({
repo,
owner,
repo: issueRepo,
owner: issueOwner,
issue_number: issueNumber,
state: 'closed'
});
}
const labels = await octokit.rest.issues.listLabelsForRepo({
repo: issueRepo,
owner: issueOwner
});
core.info(`Found ${labels.data.length} labels for the issue repo ${issueOwner}/${issueRepo}`);
const hasLabel = labels.data.some(label => label.name === LABEL);
if (!hasLabel) {
core.info(`The label "${LABEL}" does not exist for the issue repo ${issueOwner}/${issueRepo}, creating...`);
await octokit.rest.issues.createLabel({
repo: issueRepo,
owner: issueOwner,
name: LABEL,
color: 'FFFFFF'
});
}
octokit.rest.issues.addLabels({
repo,
owner,
repo: issueRepo,
owner: issueOwner,
issue_number: issueNumber,
labels: [LABEL]
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ export interface GetReferencedClosedIssuesResult {
closingIssuesReferences: {
nodes: {
number: number;
repository: {
owner: {
login: string;
};
name: string;
};
}[];
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ const MOCK_REFERENCED_CLOSED_ISSUES: GetReferencedClosedIssuesResult = {
closingIssuesReferences: {
nodes: [
{
number: 27
number: 27,
repository: {
owner: { login: 'issue-owner' },
name: 'issue-repo-name'
}
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export interface GetReferencedClosedIssuesResult {
closingIssuesReferences: {
nodes: {
number: number
repository: {
owner: { login: string }
name: string
}
}[]
}
}
Expand All @@ -57,6 +61,14 @@ export default async function getReferencedClosedIssues({
nodes {
# The issue number of the issue that was closed
number
repository {
# The owner where an issue was created
owner {
login
}
# The repo name where an issue was created
name
}
}
}
}
Expand Down
Loading

0 comments on commit ac46c03

Please sign in to comment.