Skip to content

Commit

Permalink
Add to existing Project working as expected.
Browse files Browse the repository at this point in the history
  • Loading branch information
bordoni committed Feb 17, 2024
1 parent 28d319f commit 9cdd144
Showing 1 changed file with 17 additions and 46 deletions.
63 changes: 17 additions & 46 deletions src/project-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,63 +173,34 @@ export async function projectLink(): Promise<void> {
return
}

const project = foundNodes?.edges[0]
const project = foundNodes?.edges[0]?.node

if (!project) {
core.info(`No projects found for ${issueOwnerName} with query ${queryString}`)
return
}

core.debug(`Found project: ${project.node.title} (Number: ${project.node.number})(ID: ${project.node.id})`)
core.info(`Found project: ${project.title} (Number: ${project.number})(ID: ${project.id})`)

return
// @todo implement the rest of the function
core.info('Adding PR to project')

// Next, use the GraphQL API to add the issue to the project.
// If the issue has the same owner as the project, we can directly
// add a project item. Otherwise, we add a draft issue.
if (templateProjectOwnerName && templateProjectId && issueOwnerName === templateProjectOwnerName) {
core.info('Creating project item')

const addResp = await octokit.graphql<ProjectAddItemResponse>(
`mutation addIssueToProject($input: AddProjectV2ItemByIdInput!) {
addProjectV2ItemById(input: $input) {
item {
id
}
}
}`,
{
input: {
templateProjectId,
contentId,
},
},
)

core.setOutput('itemId', addResp.addProjectV2ItemById.item.id)
} else {
core.info('Creating draft issue in project')

const addResp = await octokit.graphql<ProjectV2AddDraftIssueResponse>(
`mutation addDraftIssueToProject($projectId: ID!, $title: String!) {
addProjectV2DraftIssue(input: {
projectId: $projectId,
title: $title
}) {
projectItem {
id
}
const addResp = await octokit.graphql<ProjectAddItemResponse>(
`mutation addIssueToProject($input: AddProjectV2ItemByIdInput!) {
addProjectV2ItemById(input: $input) {
item {
id
}
}`,
{
templateProjectId,
title: issue?.html_url,
}
}`,
{
input: {
projectId: project.id,
contentId,
},
)
},
)

core.setOutput('itemId', addResp.addProjectV2DraftIssue.projectItem.id)
}
core.setOutput('itemId', addResp.addProjectV2ItemById.item.id)
}

export function mustGetOwnerTypeQuery(ownerType?: string): 'organization' | 'user' {
Expand Down

0 comments on commit 9cdd144

Please sign in to comment.