Brad
Brad

Reputation: 173

Query GitLab projects with specific field values filtered via GraphQL API

I want to find a project on Gitlab using the sshUrlToRepo or httpUrlToRepo field as a filter.

I'm trying to use the GraphQL API to do this, but am not having much success. My query, so far, looks like this:

query {
  projects(search: "url_sub_str") {
    nodes {
      id
      sshUrlToRepo
      httpUrlToRepo
    }

  }
}

This seems to filter based on url_sub_str but it's not an exact match. Is there a way to query a Gitlab project using a git remote URL of either the ssh or http variety?

Note, I'm not wedded to a GraphQL approach, a regular REST call would also do. But, ideally, I don't want to have to query a load of projects and do the search client-side. Thanks.

Upvotes: 2

Views: 865

Answers (1)

JohnDavid
JohnDavid

Reputation: 391

I would suggest if you want the exact match using

query {
  project(fullPath: "path_str") {
      id
      sshUrlToRepo
      httpUrlToRepo
  }
}

where path_str is everything between the hostname and .git https://gitlab.com/{path_str}.git

Upvotes: 0

Related Questions