Skip to content

Commit 128349a

Browse files
Merge pull request #1647 from ehuss/config-default-branch
Fetch triagebot.toml config from the default branch.
2 parents 1a9b8b8 + 4c53aa7 commit 128349a

File tree

7 files changed

+35
-26
lines changed

7 files changed

+35
-26
lines changed

src/actions.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ impl<'a> Action for Step<'a> {
109109
for repo in repos {
110110
let repository = Repository {
111111
full_name: format!("{}/{}", repo.0, repo.1),
112+
// This is unused for query.
113+
default_branch: "master".to_string(),
112114
};
113115

114116
for QueryMap { name, kind, query } in queries {

src/config.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::changelogs::ChangelogFormat;
2-
use crate::github::GithubClient;
2+
use crate::github::{GithubClient, Repository};
33
use std::collections::{HashMap, HashSet};
44
use std::fmt;
55
use std::sync::{Arc, RwLock};
@@ -209,17 +209,20 @@ pub(crate) struct ReviewSubmittedConfig {
209209
pub(crate) reviewed_label: String,
210210
}
211211

212-
pub(crate) async fn get(gh: &GithubClient, repo: &str) -> Result<Arc<Config>, ConfigurationError> {
213-
if let Some(config) = get_cached_config(repo) {
214-
log::trace!("returning config for {} from cache", repo);
212+
pub(crate) async fn get(
213+
gh: &GithubClient,
214+
repo: &Repository,
215+
) -> Result<Arc<Config>, ConfigurationError> {
216+
if let Some(config) = get_cached_config(&repo.full_name) {
217+
log::trace!("returning config for {} from cache", repo.full_name);
215218
config
216219
} else {
217-
log::trace!("fetching fresh config for {}", repo);
220+
log::trace!("fetching fresh config for {}", repo.full_name);
218221
let res = get_fresh_config(gh, repo).await;
219222
CONFIG_CACHE
220223
.write()
221224
.unwrap()
222-
.insert(repo.to_string(), (res.clone(), Instant::now()));
225+
.insert(repo.full_name.to_string(), (res.clone(), Instant::now()));
223226
res
224227
}
225228
}
@@ -246,15 +249,15 @@ fn get_cached_config(repo: &str) -> Option<Result<Arc<Config>, ConfigurationErro
246249

247250
async fn get_fresh_config(
248251
gh: &GithubClient,
249-
repo: &str,
252+
repo: &Repository,
250253
) -> Result<Arc<Config>, ConfigurationError> {
251254
let contents = gh
252-
.raw_file(repo, "master", CONFIG_FILE_NAME)
255+
.raw_file(&repo.full_name, &repo.default_branch, CONFIG_FILE_NAME)
253256
.await
254257
.map_err(|e| ConfigurationError::Http(Arc::new(e)))?
255258
.ok_or(ConfigurationError::Missing)?;
256259
let config = Arc::new(toml::from_slice::<Config>(&contents).map_err(ConfigurationError::Toml)?);
257-
log::debug!("fresh configuration for {}: {:?}", repo, config);
260+
log::debug!("fresh configuration for {}: {:?}", repo.full_name, config);
258261
Ok(config)
259262
}
260263

@@ -273,10 +276,10 @@ impl fmt::Display for ConfigurationError {
273276
ConfigurationError::Missing => write!(
274277
f,
275278
"This repository is not enabled to use triagebot.\n\
276-
Add a `triagebot.toml` in the root of the master branch to enable it."
279+
Add a `triagebot.toml` in the root of the default branch to enable it."
277280
),
278281
ConfigurationError::Toml(e) => {
279-
write!(f, "Malformed `triagebot.toml` in master branch.\n{}", e)
282+
write!(f, "Malformed `triagebot.toml` in default branch.\n{}", e)
280283
}
281284
ConfigurationError::Http(_) => {
282285
write!(f, "Failed to query configuration for this repository.")

src/github.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,7 @@ pub struct IssueSearchResult {
906906
#[derive(Clone, Debug, serde::Deserialize)]
907907
pub struct Repository {
908908
pub full_name: String,
909+
pub default_branch: String,
909910
}
910911

911912
#[derive(Copy, Clone)]
@@ -1225,12 +1226,12 @@ pub enum Event {
12251226
}
12261227

12271228
impl Event {
1228-
pub fn repo_name(&self) -> String {
1229+
pub fn repo(&self) -> &Repository {
12291230
match self {
1230-
Event::Create(event) => event.repository.full_name.clone(),
1231-
Event::IssueComment(event) => event.repository.full_name.clone(),
1232-
Event::Issue(event) => event.repository.full_name.clone(),
1233-
Event::Push(event) => event.repository.full_name.clone(),
1231+
Event::Create(event) => &event.repository,
1232+
Event::IssueComment(event) => &event.repository,
1233+
Event::Issue(event) => &event.repository,
1234+
Event::Push(event) => &event.repository,
12341235
}
12351236
}
12361237

src/handlers.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ mod rustc_commits;
4444
mod shortcut;
4545

4646
pub async fn handle(ctx: &Context, event: &Event) -> Vec<HandlerError> {
47-
let config = config::get(&ctx.github, &event.repo_name()).await;
47+
let config = config::get(&ctx.github, event.repo()).await;
48+
if let Err(e) = &config {
49+
log::warn!("failed to load configuration: {e}");
50+
}
4851
let mut errors = Vec::new();
4952

5053
if let (Ok(config), Event::Issue(event)) = (config.as_ref(), event) {

src/handlers/github_releases.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub(super) async fn handle(
3131
format!(
3232
"failed to load changelog file {} from repo {} in branch {}",
3333
config.changelog_path,
34-
event.repo_name(),
34+
event.repo().full_name,
3535
config.changelog_branch
3636
)
3737
})?;
@@ -40,7 +40,7 @@ pub(super) async fn handle(
4040
log::debug!("loading the git tags");
4141
let tags = load_paginated(
4242
ctx,
43-
&format!("repos/{}/git/matching-refs/tags", event.repo_name()),
43+
&format!("repos/{}/git/matching-refs/tags", event.repo().full_name),
4444
|git_ref: &GitRef| {
4545
git_ref
4646
.name
@@ -54,7 +54,7 @@ pub(super) async fn handle(
5454
log::debug!("loading the existing releases");
5555
let releases = load_paginated(
5656
ctx,
57-
&format!("repos/{}/releases", event.repo_name()),
57+
&format!("repos/{}/releases", event.repo().full_name),
5858
|release: &Release| release.tag_name.clone(),
5959
)
6060
.await?;
@@ -65,7 +65,7 @@ pub(super) async fn handle(
6565

6666
if let Some(release) = releases.get(tag) {
6767
if release.name != expected_name || release.body != expected_body {
68-
log::info!("updating release {} on {}", tag, event.repo_name());
68+
log::info!("updating release {} on {}", tag, event.repo().full_name);
6969
let _: serde_json::Value = ctx
7070
.octocrab
7171
.patch(
@@ -81,11 +81,11 @@ pub(super) async fn handle(
8181
continue;
8282
}
8383
} else {
84-
log::info!("creating release {} on {}", tag, event.repo_name());
84+
log::info!("creating release {} on {}", tag, event.repo().full_name);
8585
let e: octocrab::Result<serde_json::Value> = ctx
8686
.octocrab
8787
.post(
88-
format!("repos/{}/releases", event.repo_name()),
88+
format!("repos/{}/releases", event.repo().full_name),
8989
Some(&serde_json::json!({
9090
"tag_name": tag,
9191
"name": expected_name,
@@ -125,7 +125,7 @@ async fn load_changelog(
125125
let resp = ctx
126126
.github
127127
.raw_file(
128-
&event.repo_name(),
128+
&event.repo().full_name,
129129
&config.changelog_branch,
130130
&config.changelog_path,
131131
)

src/handlers/nominate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub(super) async fn handle_command(
6060
&event.issue().unwrap(),
6161
format!(
6262
"This team (`{}`) cannot be nominated for via this command;\
63-
it may need to be added to `triagebot.toml` on the master branch.",
63+
it may need to be added to `triagebot.toml` on the default branch.",
6464
cmd.team,
6565
),
6666
);

src/handlers/ping.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub(super) async fn handle_command(
4141
&event.issue().unwrap(),
4242
format!(
4343
"This team (`{}`) cannot be pinged via this command; \
44-
it may need to be added to `triagebot.toml` on the master branch.",
44+
it may need to be added to `triagebot.toml` on the default branch.",
4545
team_name.team,
4646
),
4747
);

0 commit comments

Comments
 (0)