Skip to content

Commit 9e083ed

Browse files
Add headRepositoryOwner to GraphQL query and GhPr struct
Fetch `headRepositoryOwner { login }` in the PR GraphQL query and store it as `head_repo_owner: Option<String>` on GhPr. This enables future filtering/disambiguation for fork-based workflows where multiple users might have branches with the same name. Co-authored-by: Infinity 🤖 <infinity@hydro.run> PR: #36
1 parent 5c241c2 commit 9e083ed

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/gh.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ pub struct GhPr {
6060
pub is_draft: bool,
6161
pub url: String,
6262
pub title: String,
63+
/// The owner (user/org) of the head repository (fork). None if same repo.
64+
#[serde(default)]
65+
pub head_repo_owner: Option<String>,
6366
}
6467

6568
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
@@ -69,7 +72,7 @@ pub struct PrStatus {
6972
}
7073

7174
/// GraphQL fields for a PR node, used in query construction.
72-
const PR_NODE_FIELDS: &str = "number headRefName baseRefName state isDraft url title reviewDecision commits(last:1) { nodes { commit { statusCheckRollup { state } } } }";
75+
const PR_NODE_FIELDS: &str = "number headRefName baseRefName state isDraft url title reviewDecision headRepositoryOwner { login } commits(last:1) { nodes { commit { statusCheckRollup { state } } } }";
7376

7477
/// Raw GraphQL response types for serde deserialization.
7578
#[derive(Deserialize)]
@@ -144,9 +147,15 @@ struct PrNode {
144147
url: String,
145148
title: String,
146149
review_decision: Option<ReviewDecision>,
150+
head_repository_owner: Option<HeadRepoOwner>,
147151
commits: CommitsConnection,
148152
}
149153

154+
#[derive(Deserialize)]
155+
struct HeadRepoOwner {
156+
login: String,
157+
}
158+
150159
#[derive(Deserialize)]
151160
struct CommitsConnection {
152161
nodes: Vec<CommitNode>,
@@ -281,6 +290,7 @@ pub fn load_prs_and_default_branch(
281290
is_draft: d.is_draft,
282291
url: d.url,
283292
title: d.title,
293+
head_repo_owner: d.head_repository_owner.map(|o| o.login),
284294
});
285295
}
286296

src/tests.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ fn gh_pr(number: u64, head: &str, base: &str) -> GhPr {
161161
is_draft: true,
162162
url: format!("https://github.com/test/repo/pull/{number}"),
163163
title: format!("PR #{number}"),
164+
head_repo_owner: None,
164165
}
165166
}
166167

@@ -174,6 +175,7 @@ fn gh_pr_merged(number: u64, head: &str, base: &str) -> GhPr {
174175
is_draft: false,
175176
url: format!("https://github.com/test/repo/pull/{number}"),
176177
title: format!("PR #{number}"),
178+
head_repo_owner: None,
177179
}
178180
}
179181

@@ -187,6 +189,7 @@ fn gh_pr_closed(number: u64, head: &str, base: &str) -> GhPr {
187189
is_draft: false,
188190
url: format!("https://github.com/test/repo/pull/{number}"),
189191
title: format!("PR #{number}"),
192+
head_repo_owner: None,
190193
}
191194
}
192195

0 commit comments

Comments
 (0)