From 1f3fc2fe96d9fc50081525de9607fca32faffb0c Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Wed, 9 Jun 2021 10:44:14 +0900 Subject: [PATCH] Use `GITHUB_TOKEN` to label issues on this repo (#821) --- .github/workflows/labeler.yml | 1 + labeler/src/github.rs | 17 +++++++++++++---- labeler/src/main.rs | 10 ++++++++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml index f5d64b13..a4725b6c 100644 --- a/.github/workflows/labeler.yml +++ b/.github/workflows/labeler.yml @@ -22,3 +22,4 @@ jobs: run: cargo run -p labeler env: LABEL_TOKEN: ${{ secrets.LABEL_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/labeler/src/github.rs b/labeler/src/github.rs index ce5a7650..8b2b880a 100644 --- a/labeler/src/github.rs +++ b/labeler/src/github.rs @@ -16,9 +16,13 @@ pub(crate) struct Config { } impl Config { - pub(crate) fn from_env() -> Result { + pub(crate) fn from_env(on_glacier: bool) -> Result { Ok(Self { - token: var("LABEL_TOKEN")?, + token: if on_glacier { + var("GITHUB_TOKEN")? + } else { + var("LABEL_TOKEN")? + }, }) } } @@ -48,7 +52,11 @@ pub(crate) fn create_issue( }) .send()?; if let Err(err) = resp.error_for_status_ref() { - eprintln!("Failed to create issue, err: `{:?}`, server response: `{:?}`", err, resp.text()); + eprintln!( + "Failed to create issue, err: `{:?}`, server response: `{:?}`", + err, + resp.text() + ); return Err(err); } @@ -121,7 +129,8 @@ fn get_result_length(config: &Config, url: &str) -> Result; rel="last""#).unwrap()); + let re_last_page = + RE_LAST_PAGE.get_or_init(|| Regex::new(r#"page=([0-9]+)>; rel="last""#).unwrap()); let last_page_number = re_last_page .captures(&link_string) .unwrap() diff --git a/labeler/src/main.rs b/labeler/src/main.rs index b0f475cf..7fe83049 100644 --- a/labeler/src/main.rs +++ b/labeler/src/main.rs @@ -3,9 +3,13 @@ use crate::github::IssueState; mod github; fn main() { - let config = github::Config::from_env().unwrap(); + let config = github::Config::from_env(false).unwrap(); - let mut tested_issue_list = glacier::discover("./ices").unwrap().into_iter().map(|ice| ice.id()).collect::>(); + let mut tested_issue_list = glacier::discover("./ices") + .unwrap() + .into_iter() + .map(|ice| ice.id()) + .collect::>(); tested_issue_list.sort_unstable(); tested_issue_list.dedup(); println!("current tested issue list: {:?}", tested_issue_list); @@ -45,6 +49,8 @@ fn main() { } } + // Then we use `GITHUB_TOKEN` instead of `LABEL_TOKEN`. + let config = github::Config::from_env(true).unwrap(); let issues_in_triage = crate::github::get_labeled_issues(&config, "rust-lang/glacier", "triage".to_string()) .unwrap();