Skip to content

Commit

Permalink
Fix PullRequestQuery GraphQL query for repositories not owned by orgs
Browse files Browse the repository at this point in the history
GitHub repositories can be owned by users or orgs. The way the PullRequestQuery was phrased it threw an error if the repository used was owned by a user. This commit fixes that.

Test Plan:
update an existing PR in repositories both owned by a user and an org.

Reviewers: jozef-mokry

Reviewed By: jozef-mokry

Pull Request: #46
  • Loading branch information
Sven Over authored May 26, 2022
1 parent 0726b07 commit dc2e667
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 37 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [1.2.4] - 2022-05-26

### Fixes

- fix working with repositories not owned by an organization but by a user

## [1.2.3] - 2022-05-24

### Fixes
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "spr"
version = "1.2.3"
version = "1.2.4"
authors = ["Sven Over <[email protected]>", "Jozef Mokry <[email protected]>"]
description = "Submit pull requests for individual, amendable, rebaseable commits to GitHub"
repository = "https://github.com/getcord/spr"
Expand Down
4 changes: 1 addition & 3 deletions src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,6 @@ impl GitHub {
let pr = response_body
.data
.ok_or_else(|| Error::new("failed to fetch PR"))?
.organization
.ok_or_else(|| Error::new("failed to find organization"))?
.repository
.ok_or_else(|| Error::new("failed to find repository"))?
.pull_request
Expand Down Expand Up @@ -253,7 +251,7 @@ impl GitHub {
.flatten()
.flat_map(|x| &x.requested_reviewer)
.flat_map(|reviewer| {
type UserType = pull_request_query::PullRequestQueryOrganizationRepositoryPullRequestReviewRequestsNodesRequestedReviewer;
type UserType = pull_request_query::PullRequestQueryRepositoryPullRequestReviewRequestsNodesRequestedReviewer;
match reviewer {
UserType::User(user) => Some(user.login.clone()),
UserType::Team(team) => Some(format!("#{}", team.slug)),
Expand Down
62 changes: 30 additions & 32 deletions src/gql/pullrequest_query.graphql
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
query PullRequestQuery($name: String!, $owner: String!, $number: Int!) {
organization(login: $owner) {
repository(name: $name) {
pullRequest(number: $number) {
number
state
reviewDecision
title
body
baseRefName
baseRefOid
headRefOid
headRefName
mergeCommit {
oid
}
latestOpinionatedReviews(last: 100) {
nodes {
author {
__typename
login
}
state
repository(owner: $owner, name: $name) {
pullRequest(number: $number) {
number
state
reviewDecision
title
body
baseRefName
baseRefOid
headRefOid
headRefName
mergeCommit {
oid
}
latestOpinionatedReviews(last: 100) {
nodes {
author {
__typename
login
}
state
}
reviewRequests(last: 100) {
nodes {
requestedReviewer {
__typename
... on Team {
slug
}
... on User {
login
}
}
reviewRequests(last: 100) {
nodes {
requestedReviewer {
__typename
... on Team {
slug
}
... on User {
login
}
}
}
Expand Down

0 comments on commit dc2e667

Please sign in to comment.