pksunkara / octonode

github api v3 in nodejs
MIT License
1.19k stars 237 forks source link

Add issue to a project? #361

Open nickiannone-tw opened 2 years ago

nickiannone-tw commented 2 years ago

I've got a Hubot instance with a set of scripts which use octonode to sync Slack messages with GitHub Enterprise issues. I'm trying to add a piece of code to add an Issue to an existing Project, and let it auto-triage to To Do status, but I'm unable to achieve this by setting the project field on the issue and using the update method. How would I add this Issue to a Project with a known ID?

Current (non-working) code:

issue = client().issue REPO, id
project = client().project REPO, 1 # We want <repo>/projects/1!
issue.update { project: project }, (err, data, headers) ->
  unless err?
    res.send "Added issue ##{id} to project 1"
  else
    res.reply "Error"

I'm getting the success response from my GHE instance, but the issue isn't being assigned to the project. Is there another way to assign an issue to a project, or is this just currently unsupported?

nickiannone-tw commented 2 years ago

Possible alternative (haven't read through it yet): https://www.cloudwithchris.com/blog/automate-adding-gh-issues-projects-beta/

nickiannone-tw commented 2 years ago

Okay, so it looks like we have to get the project, list its columns, and PUT a new Card onto the project at that column. Not sure if there's a default auto-triage column abstraction which is listed somewhere, which corresponds to the default behavior on the web interface, but I'll experiment to find out.

Web interface:

Actions:

Expected Outcome:

nickiannone-tw commented 2 years ago

Get project: https://docs.github.com/en/rest/projects/projects#get-a-project

List its columns: https://docs.github.com/en/rest/projects/columns#list-project-columns

Find auto-triage column: ???

Create a card: https://docs.github.com/en/rest/projects/cards#create-a-project-card

After these steps, the issue should show the project and column on the Issue view in GHE, I just need to confirm.

pksunkara commented 2 years ago

Find auto-triage column: ???

I don't think I can help you with this. I think the column's probably named by default as "To Do"

nickiannone-tw commented 2 years ago

Why was this closed? We don't have a way to get the columns in a project, and I was going to add one to a new PR...

We still need to add support in Octonode for these endpoints, in order to achieve this functionality:

nickiannone-tw commented 2 years ago

I've got a few hours this evening I can set aside to spin up a PR for this; testing should be pretty much identical to what's already done, so I can probably close this out by end of week.

nickiannone-tw commented 2 years ago

Thanks; sorry for not being clearer with the original request. I'll dig into this in a few hours and see where I get in a few pomodoro cycles.

pksunkara commented 2 years ago

FWIW, I would suggest using client.get and other such methods to build custom API calls. I am fine if you want to make a PR to the project to actually add those APIs too but I am just pointing out that we have a general abstraction that you can use.