Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull Request when created add to project by default #931

Closed
rthadur opened this issue May 5, 2019 · 14 comments

Comments

@rthadur
Copy link

commented May 5, 2019

Bug Report

Hi I Don't see how we can add a PR when created to project using probot.I would like to request this feature if this implementation does not exist.

@issue-label-bot

This comment was marked as resolved.

Copy link

commented May 5, 2019

Issue-Label Bot is automatically applying the label enhancement ➕ to this issue, with a confidence of 0.82. Please mark this comment with 👍 or 👎 to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

@gr2m

This comment has been minimized.

Copy link
Contributor

commented May 6, 2019

Probot implements all methods from @octokit/rest: https://github.com/octokit/rest.js, such as creating a pull request: https://octokit.github.io/rest.js/#octokit-routes-pulls-create

The octokit instance is context.github in the event handlers, so you can do

module.exports = app => {
  app.on('issues.opened', async context => {
    context.github.pulls.create({
      owner,
      repo,
      title,
      head,
      base
    })
  })
}

You can replace 'issues.opened' with whatever event/action you need

GitHub
GitHub REST API client for JavaScript. Contribute to octokit/rest.js development by creating an account on GitHub.

@gr2m gr2m added support and removed enhancement labels May 6, 2019

@rthadur

This comment has been minimized.

Copy link
Author

commented May 6, 2019

Thanks you greg, but iam looking a method where i can add PR to a existing project.

@gr2m

This comment has been minimized.

Copy link
Contributor

commented May 6, 2019

Got it, sorry I misunderstood your issue description.

The context.github.projects.createCard(options) method seems to be what you are looking for.

const COLUMN_ID = 123 // set to ID of column where you want the card to be added

module.exports = app => {
  app.on('pull_request.created', async context => {
    octokit.projects.createCard({
      column_id: COLUMN_ID,
      content_type: 'PullRequest',
      content_id: context.payload.pull_request.id
    })
}
@rthadur

This comment has been minimized.

Copy link
Author

commented May 6, 2019

thank you it worked, when i set content_id iam getting this error ,

{"message":"Validation Failed","errors":[{"resource":"ProjectCard","code":"unprocessable","field":"data","message":"Could not resolve to a node with the global id of 'MDExOlB1bGxSZXF1ZXN0MTk0'."}],"documentation_url":"https://developer.github.com/v3/projects/cards/#create-a-project-card"}

note: iam setting PR number

@gr2m

This comment has been minimized.

Copy link
Contributor

commented May 7, 2019

MDExOlB1bGxSZXF1ZXN0MTk0 is a node ID, used in GraphQL. You need to set content_id to the databaseId of the pull request, not the number.

Same with column_id, it has to be set to the database ID, not node id

@rthadur

This comment has been minimized.

Copy link
Author

commented May 7, 2019

where can i find database ID for both column_id and content_id , sorry if this is too basic.

code you mentioned above is trying to create a card i guess , iam trying to add a newly opened PR to existing project card.

@gr2m

This comment has been minimized.

Copy link
Contributor

commented May 7, 2019

I don't think that an existing project card can be altered, there is no REST API endpoint for that: https://developer.github.com/v3/projects/cards/#update-a-project-card

Please ask support@github.com, maybe I miss something

GitHub Developer
Get started with one of our guides, or jump straight into the API documentation.
@rthadur

This comment has been minimized.

Copy link
Author

commented May 7, 2019

Thank you greg , i don't want to alter but add the PR to "in-progress" card in project

@gr2m

This comment has been minimized.

Copy link
Contributor

commented May 7, 2019

Tell me the steps you currently do manually to achieve what you want

@rthadur

This comment has been minimized.

Copy link
Author

commented May 7, 2019

sure

  1. Identify open PR which is not yet reviewed and assign to me.

  2. Add reviewer

  3. Add to project
    image

  4. Then review the PR

@rthadur

This comment has been minimized.

Copy link
Author

commented May 9, 2019

@gr2m did you get a chance to check above comment.

@gr2m

This comment has been minimized.

Copy link
Contributor

commented May 9, 2019

I don’t think there is an API endpoint which allows to add a pull request / issue to an existing project. You will need to use

octokit.projects.createCard({
  column_id,
  content_id,
  content_type: 'PullRequest'
})

Just as I described in #931 (comment)

@gr2m gr2m closed this May 9, 2019

@rthadur

This comment has been minimized.

Copy link
Author

commented May 9, 2019

Thank you , it is working as expected.
But only thing is it is throwing error here which is not blocking regular functionality,
TypeError: Cannot read property 'id' of undefined
at this line "content_id: context.payload.pull_request.id"
at Application.(node_modules/probot/lib/application.js:185:50)
at step (/node_modules/probot/lib/application.js:40:23)
at Object.next (node_modules/probot/lib/application.js:21:53)
at fulfilled (/node_modules/probot/lib/application.js:12:58)
at process._tickCallback (internal/process/next_tick.js:68:7)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.