IssueOrPullRequestID returns the ID of the issue or pull request from a URL.
(rawURL string)
| 1255 | |
| 1256 | // IssueOrPullRequestID returns the ID of the issue or pull request from a URL. |
| 1257 | func (c *Client) IssueOrPullRequestID(rawURL string) (string, error) { |
| 1258 | uri, err := url.Parse(rawURL) |
| 1259 | if err != nil { |
| 1260 | return "", err |
| 1261 | } |
| 1262 | variables := map[string]interface{}{ |
| 1263 | "url": githubv4.URI{URL: uri}, |
| 1264 | } |
| 1265 | var query issueOrPullRequest |
| 1266 | err = c.doQueryWithProgressIndicator("GetIssueOrPullRequest", &query, variables) |
| 1267 | if err != nil { |
| 1268 | return "", err |
| 1269 | } |
| 1270 | if query.Resource.Typename == "Issue" { |
| 1271 | return query.Resource.Issue.ID, nil |
| 1272 | } else if query.Resource.Typename == "PullRequest" { |
| 1273 | return query.Resource.PullRequest.ID, nil |
| 1274 | } |
| 1275 | return "", errors.New("resource not found, please check the URL") |
| 1276 | } |
| 1277 | |
| 1278 | // userProjects queries the $first projects of a user. |
| 1279 | type userProjects struct { |
no test coverage detected