Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2883,6 +2883,35 @@ impl GithubClient {
};
Ok(repo_id)
}

/// Returns the number of issues or PRs that match the given query.
///
/// See
/// <https://docs.github.com/en/search-github/searching-on-github/searching-issues-and-pull-requests>
/// and
/// <https://docs.github.com/en/search-github/getting-started-with-searching-on-github/understanding-the-search-syntax>
/// for the query syntax.
pub async fn issue_search_count(&self, query: &str) -> anyhow::Result<u64> {
let data = self
.graphql_query(
"query($query: String!) {
search(query: $query, type: ISSUE, first: 0) {
issueCount
}
}",
serde_json::json!({
"query": query,
}),
)
.await?;
if let serde_json::Value::Number(count) = &data["data"]["search"]["issueCount"]
&& let Some(count) = count.as_u64()
{
Ok(count)
} else {
anyhow::bail!("expected issue count, got {data}");
}
}
}

#[derive(Debug, serde::Deserialize)]
Expand Down
18 changes: 18 additions & 0 deletions src/handlers/docs_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ impl Job for DocsUpdateJob {

pub async fn docs_update() -> Result<Option<Issue>> {
let gh = GithubClient::new_from_env();

if is_pr_already_open(&gh)
.await
.context("failed to determine if a PR is already open for updating the docs")?
{
tracing::trace!("pr is already open");
return Ok(None);
}

let dest_repo = gh.repository(DEST_REPO).await?;
let work_repo = gh.repository(WORK_REPO).await?;

Expand All @@ -78,6 +87,15 @@ pub async fn docs_update() -> Result<Option<Issue>> {
Ok(Some(create_pr(&gh, &dest_repo, &updates).await?))
}

async fn is_pr_already_open(gh: &GithubClient) -> Result<bool> {
let count = gh
.issue_search_count(&format!(
"repo:{DEST_REPO} is:pr is:open author:rustbot head:{BRANCH_NAME}"
))
.await?;
Ok(count != 0)
}

struct Update {
path: String,
new_hash: String,
Expand Down