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

Commit 1f3fc2f

Browse files
authored
Use GITHUB_TOKEN to label issues on this repo (#821)
1 parent 9ddab6c commit 1f3fc2f

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

.github/workflows/labeler.yml

+1
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ jobs:
2222
run: cargo run -p labeler
2323
env:
2424
LABEL_TOKEN: ${{ secrets.LABEL_TOKEN }}
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

labeler/src/github.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ pub(crate) struct Config {
1616
}
1717

1818
impl Config {
19-
pub(crate) fn from_env() -> Result<Self, VarError> {
19+
pub(crate) fn from_env(on_glacier: bool) -> Result<Self, VarError> {
2020
Ok(Self {
21-
token: var("LABEL_TOKEN")?,
21+
token: if on_glacier {
22+
var("GITHUB_TOKEN")?
23+
} else {
24+
var("LABEL_TOKEN")?
25+
},
2226
})
2327
}
2428
}
@@ -48,7 +52,11 @@ pub(crate) fn create_issue(
4852
})
4953
.send()?;
5054
if let Err(err) = resp.error_for_status_ref() {
51-
eprintln!("Failed to create issue, err: `{:?}`, server response: `{:?}`", err, resp.text());
55+
eprintln!(
56+
"Failed to create issue, err: `{:?}`, server response: `{:?}`",
57+
err,
58+
resp.text()
59+
);
5260
return Err(err);
5361
}
5462

@@ -121,7 +129,8 @@ fn get_result_length(config: &Config, url: &str) -> Result<usize, Box<dyn std::e
121129
if res.status().is_success() {
122130
if let Some(link) = res.headers().get("Link") {
123131
let link_string = String::from_utf8(link.as_bytes().to_vec()).unwrap();
124-
let re_last_page = RE_LAST_PAGE.get_or_init(|| Regex::new(r#"page=([0-9]+)>; rel="last""#).unwrap());
132+
let re_last_page =
133+
RE_LAST_PAGE.get_or_init(|| Regex::new(r#"page=([0-9]+)>; rel="last""#).unwrap());
125134
let last_page_number = re_last_page
126135
.captures(&link_string)
127136
.unwrap()

labeler/src/main.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ use crate::github::IssueState;
33
mod github;
44

55
fn main() {
6-
let config = github::Config::from_env().unwrap();
6+
let config = github::Config::from_env(false).unwrap();
77

8-
let mut tested_issue_list = glacier::discover("./ices").unwrap().into_iter().map(|ice| ice.id()).collect::<Vec<_>>();
8+
let mut tested_issue_list = glacier::discover("./ices")
9+
.unwrap()
10+
.into_iter()
11+
.map(|ice| ice.id())
12+
.collect::<Vec<_>>();
913
tested_issue_list.sort_unstable();
1014
tested_issue_list.dedup();
1115
println!("current tested issue list: {:?}", tested_issue_list);
@@ -45,6 +49,8 @@ fn main() {
4549
}
4650
}
4751

52+
// Then we use `GITHUB_TOKEN` instead of `LABEL_TOKEN`.
53+
let config = github::Config::from_env(true).unwrap();
4854
let issues_in_triage =
4955
crate::github::get_labeled_issues(&config, "rust-lang/glacier", "triage".to_string())
5056
.unwrap();

0 commit comments

Comments
 (0)