Update project_automation.yml
This commit is contained in:
parent
4f4e1a3459
commit
ffc990da70
|
|
@ -112,14 +112,14 @@ jobs:
|
||||||
console.log(`Close Reason: ${closeReason}`);
|
console.log(`Close Reason: ${closeReason}`);
|
||||||
let statusValue = '';
|
let statusValue = '';
|
||||||
let labelToAdd = '';
|
let labelToAdd = '';
|
||||||
let shouldArchive = false;
|
let shouldRemove = false;
|
||||||
|
|
||||||
if (closeReason === 'not_planned') {
|
if (closeReason === 'not_planned') {
|
||||||
labelToAdd = 'wontfix';
|
labelToAdd = 'wontfix';
|
||||||
shouldArchive = true;
|
shouldRemove = true;
|
||||||
} else if (closeReason === 'duplicate') {
|
} else if (closeReason === 'duplicate') {
|
||||||
labelToAdd = 'duplicate';
|
labelToAdd = 'duplicate';
|
||||||
shouldArchive = true;
|
shouldRemove = true;
|
||||||
} else if (closeReason === 'completed') {
|
} else if (closeReason === 'completed') {
|
||||||
statusValue = process.env.done;
|
statusValue = process.env.done;
|
||||||
}
|
}
|
||||||
|
|
@ -146,100 +146,78 @@ jobs:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle project actions (add to project, update status, or archive)
|
// Remove the project item if needed
|
||||||
try {
|
if (shouldRemove) {
|
||||||
// Fetch project node ID
|
try {
|
||||||
const projectData = await github.graphql(`
|
// Fetch project node ID
|
||||||
query($org: String!, $projectNumber: Int!) {
|
const projectData = await github.graphql(`
|
||||||
organization(login: $org) {
|
query($org: String!, $projectNumber: Int!) {
|
||||||
projectV2(number: $projectNumber) {
|
organization(login: $org) {
|
||||||
id
|
projectV2(number: $projectNumber) {
|
||||||
|
id
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
`, {
|
||||||
`, {
|
org: 'ghostbsd',
|
||||||
org: 'ghostbsd',
|
projectNumber: 4
|
||||||
projectNumber: 4
|
});
|
||||||
});
|
|
||||||
|
|
||||||
const projectId = projectData.organization.projectV2.id;
|
const projectId = projectData.organization.projectV2.id;
|
||||||
console.log(`Project ID: ${projectId}`);
|
console.log(`Project ID: ${projectId}`);
|
||||||
|
|
||||||
// Fetch project items
|
// Fetch project items
|
||||||
const projectItems = await github.graphql(`
|
const projectItems = await github.graphql(`
|
||||||
query($org: String!, $projectNumber: Int!) {
|
query($org: String!, $projectNumber: Int!) {
|
||||||
organization(login: $org) {
|
organization(login: $org) {
|
||||||
projectV2(number: $projectNumber) {
|
projectV2(number: $projectNumber) {
|
||||||
items(first: 1000) {
|
items(first: 100) {
|
||||||
nodes {
|
nodes {
|
||||||
id
|
id
|
||||||
content {
|
content {
|
||||||
... on Issue {
|
... on Issue {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
... on PullRequest {
|
... on PullRequest {
|
||||||
id
|
id
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
`, {
|
|
||||||
org: 'ghostbsd',
|
|
||||||
projectNumber: 4
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(`Project items fetched: ${projectItems.organization.projectV2.items.nodes.length} items`);
|
|
||||||
let projectItem = projectItems.organization.projectV2.items.nodes.find(
|
|
||||||
item => item.content.id === nodeId
|
|
||||||
);
|
|
||||||
|
|
||||||
// If item is not in project, add it
|
|
||||||
if (!projectItem) {
|
|
||||||
console.log(`Item with node ID ${nodeId} not found in project 4, adding it`);
|
|
||||||
const addItem = await github.graphql(`
|
|
||||||
mutation($projectId: ID!, $contentId: ID!) {
|
|
||||||
addProjectV2ItemById(input: { projectId: $projectId, contentId: $contentId }) {
|
|
||||||
item {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`, {
|
`, {
|
||||||
projectId: projectId,
|
org: 'ghostbsd',
|
||||||
contentId: nodeId
|
projectNumber: 4
|
||||||
});
|
});
|
||||||
console.log(`Added item with node ID ${nodeId} to project 4, item ID: ${addItem.addProjectV2ItemById.item.id}`);
|
|
||||||
projectItem = { id: addItem.addProjectV2ItemById.item.id };
|
|
||||||
}
|
|
||||||
|
|
||||||
// Archive the project item if needed
|
console.log(`Project items fetched: ${projectItems.organization.projectV2.items.nodes.length} items`);
|
||||||
if (shouldArchive) {
|
const projectItem = projectItems.organization.projectV2.items.nodes.find(
|
||||||
try {
|
item => item.content.id === nodeId
|
||||||
|
);
|
||||||
|
|
||||||
|
if (projectItem) {
|
||||||
await github.graphql(`
|
await github.graphql(`
|
||||||
mutation($projectId: ID!, $itemId: ID!) {
|
mutation($projectId: ID!, $itemId: ID!) {
|
||||||
archiveProjectV2Item(input: { projectId: $projectId, itemId: $itemId }) {
|
deleteProjectV2Item(input: { projectId: $projectId, itemId: $itemId }) {
|
||||||
item {
|
deletedItemId
|
||||||
id
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`, {
|
`, {
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
itemId: projectItem.id
|
itemId: projectItem.id
|
||||||
});
|
});
|
||||||
console.log(`Archived item with node ID ${nodeId} in project 4`);
|
console.log(`Removed item with node ID ${nodeId} from project 4`);
|
||||||
} catch (error) {
|
} else {
|
||||||
console.log(`Failed to archive item: ${error.message}`);
|
console.log(`Item with node ID ${nodeId} not found in project 4`);
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(`Failed to remove item: ${error.message}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
core.setOutput('close_reason', closeReason);
|
|
||||||
} catch (error) {
|
|
||||||
console.log(`Failed to manage project item: ${error.message}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core.setOutput('close_reason', closeReason);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(`Failed to fetch issue/PR: ${error.message}`);
|
console.log(`Failed to fetch issue/PR: ${error.message}`);
|
||||||
throw error;
|
throw error;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue