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

[Feature Request] List Projects a Pull Request belongs to #211

Open
jasongaare opened this issue Sep 23, 2022 · 1 comment
Open

[Feature Request] List Projects a Pull Request belongs to #211

jasongaare opened this issue Sep 23, 2022 · 1 comment
Labels
Type: Support Any questions, information, or general needs around the SDK or GitHub APIs
Projects

Comments

@jasongaare
Copy link

What’s missing?

When getting information for a pull request, I cannot seem to determine what Projects the PR belongs to. I can find things like milestone but not projects.

Why?

I want to write an Action to require all PRs belong to a GitHub Project.

Alternatives you tried

My current workaround is as follows:

  • get a list of all "open" projects for the repository
  • for each open project, get a list of all columns
  • for each column, get a list of all cards
  • compare EACH card (there are MANY) and look at the card's content_url and compare it to a PR's issue link.

This seems very overkill! Is there another way?

We are using Projects (Classic) by the way... so wondering if that API is on its way out regardless?

@jasongaare jasongaare added the Type: Feature New feature or request label Sep 23, 2022
@ghost ghost added this to Features in JS Sep 23, 2022
@gr2m
Copy link
Contributor

gr2m commented Sep 26, 2022

This is out of scope for @octokit/rest as there is no GitHub REST API for that specific use case that I'm aware of.

But I think you can probably achieve it with a GraphQL Query

const query = `query { 
  pullRequest:resource(url:$pull_request_url) {
    ... on PullRequest {
      projectCards {
        nodes {
          project {
            name
          }
        }
      }
    }
  }
}`
const result = octokit.graphql(query, { pull_request_url: "https://github.com/octokit/core.js/pull/522" })
const projectNames = result.pullRequest.projectCards.nodes.map(card => card.project.name)

Once you figure out the code, you could create an Octokit plugin to make it easier to share it with others:
https://github.com/octokit/core.js#plugins

@gr2m gr2m added Type: Support Any questions, information, or general needs around the SDK or GitHub APIs and removed Type: Feature New feature or request labels Sep 26, 2022
@ghost ghost moved this from Features to Support in JS Sep 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Support Any questions, information, or general needs around the SDK or GitHub APIs
Projects
No open projects
JS
  
Support
Development

No branches or pull requests

2 participants