Skip to content

Commit 8ffd950

Browse files
authored
Merge pull request #2161 from ehuss/fix-merge-conflicts
Fix merge conflict detection
2 parents b8ef575 + 9c54f9b commit 8ffd950

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

src/github.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,6 +1981,16 @@ impl Repository {
19811981
.with_context(|| format!("{} failed to get issue {issue_num}", self.full_name))
19821982
}
19831983

1984+
pub async fn get_pr(&self, client: &GithubClient, pr_num: u64) -> anyhow::Result<Issue> {
1985+
let url = format!("{}/pulls/{pr_num}", self.url(client));
1986+
let mut pr: Issue = client
1987+
.json(client.get(&url))
1988+
.await
1989+
.with_context(|| format!("{} failed to get pr {pr_num}", self.full_name))?;
1990+
pr.pull_request = Some(PullRequestDetails::new());
1991+
Ok(pr)
1992+
}
1993+
19841994
/// Fetches information about merge conflicts on open PRs.
19851995
pub async fn get_merge_conflict_prs(
19861996
&self,

src/handlers/merge_conflicts.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,17 @@ async fn rescan_pr(
140140
repo: Repository,
141141
pr_number: u64,
142142
) -> anyhow::Result<()> {
143-
let issue = repo.get_issue(gh, pr_number).await?;
143+
let pr = repo.get_pr(gh, pr_number).await?;
144144
log::debug!(
145145
"re-scanning unknown PR {} for merge conflict after delay",
146-
issue.global_id()
146+
pr.global_id()
147147
);
148-
match issue.mergeable {
149-
Some(true) => maybe_hide_comment(gh, &mut db, &issue).await?,
150-
Some(false) => maybe_add_comment(gh, &mut db, config, &issue, None).await?,
148+
match pr.mergeable {
149+
Some(true) => maybe_hide_comment(gh, &mut db, &pr).await?,
150+
Some(false) => maybe_add_comment(gh, &mut db, config, &pr, None).await?,
151151
None => log::info!(
152152
"re-scan of mergeable status still unknown for {}",
153-
issue.global_id()
153+
pr.global_id()
154154
),
155155
}
156156
Ok(())
@@ -205,8 +205,8 @@ async fn scan_prs(
205205
.partition(|pr| pr.mergeable == MergeableState::Conflicting);
206206

207207
for conflict in conflicting {
208-
let issue = repo.get_issue(gh, conflict.number).await?;
209-
maybe_add_comment(gh, &mut db, config, &issue, possibly.as_deref()).await?;
208+
let pr = repo.get_pr(gh, conflict.number).await?;
209+
maybe_add_comment(gh, &mut db, config, &pr, possibly.as_deref()).await?;
210210
}
211211
if !unknowns.is_empty() {
212212
let config = config.clone();
@@ -243,11 +243,11 @@ async fn scan_unknowns(
243243
repo.full_name
244244
);
245245
for unknown in unknowns {
246-
let issue = repo.get_issue(&gh, unknown.number).await?;
246+
let pr = repo.get_pr(&gh, unknown.number).await?;
247247
// Ignore None, we don't want to repeatedly hammer GitHub asking for the answer.
248-
if issue.mergeable == Some(false) {
249-
maybe_add_comment(gh, &mut db, config, &issue, possibly.as_deref()).await?;
250-
} else if issue.mergeable == None {
248+
if pr.mergeable == Some(false) {
249+
maybe_add_comment(gh, &mut db, config, &pr, possibly.as_deref()).await?;
250+
} else if pr.mergeable == None {
251251
log::info!("unable to determine mergeable after delay for {unknown:?}");
252252
}
253253
}

0 commit comments

Comments
 (0)