Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Commit

Permalink
Use GITHUB_TOKEN to label issues on this repo (#821)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnTitor authored Jun 9, 2021
1 parent 9ddab6c commit 1f3fc2f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ jobs:
run: cargo run -p labeler
env:
LABEL_TOKEN: ${{ secrets.LABEL_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17 changes: 13 additions & 4 deletions labeler/src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ pub(crate) struct Config {
}

impl Config {
pub(crate) fn from_env() -> Result<Self, VarError> {
pub(crate) fn from_env(on_glacier: bool) -> Result<Self, VarError> {
Ok(Self {
token: var("LABEL_TOKEN")?,
token: if on_glacier {
var("GITHUB_TOKEN")?
} else {
var("LABEL_TOKEN")?
},
})
}
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -121,7 +129,8 @@ fn get_result_length(config: &Config, url: &str) -> Result<usize, Box<dyn std::e
if res.status().is_success() {
if let Some(link) = res.headers().get("Link") {
let link_string = String::from_utf8(link.as_bytes().to_vec()).unwrap();
let re_last_page = RE_LAST_PAGE.get_or_init(|| Regex::new(r#"page=([0-9]+)>; 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()
Expand Down
10 changes: 8 additions & 2 deletions labeler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>();
let mut tested_issue_list = glacier::discover("./ices")
.unwrap()
.into_iter()
.map(|ice| ice.id())
.collect::<Vec<_>>();
tested_issue_list.sort_unstable();
tested_issue_list.dedup();
println!("current tested issue list: {:?}", tested_issue_list);
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 1f3fc2f

Please sign in to comment.