Fix token naming so we can do github actions faster

This commit is contained in:
Tom Parker-Shemilt 2022-06-11 10:40:33 +01:00
parent 6a17b26a58
commit 807c4cd6dd
4 changed files with 10 additions and 9 deletions

View file

@ -11,6 +11,6 @@ jobs:
- name: Automatic Approve
uses: mheap/automatic-approve-action@v1.1.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ secrets.TOKEN_FOR_GITHUB }}
workflows: "rust.yml,lint.yml"
dangerous_files: src/main.rs,Cargo.toml,Cargo.lock

View file

@ -40,5 +40,6 @@ jobs:
- name: Run
run: cargo run
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
USERNAME_FOR_GITHUB: ${{ secrets.USERNAME_FOR_GITHUB }}
TOKEN_FOR_GITHUB: ${{ secrets.TOKEN_FOR_GITHUB }}
RUST_LOG: warn

View file

@ -87,8 +87,8 @@ async fn get_hacktoberfest_core(github_url: String) -> Result<Info, CheckerError
.replace_all(&github_url, "https://api.github.com/repos/$org/$repo")
.to_string();
let mut req = CLIENT.get(&rewritten);
if let Ok(username) = env::var("GITHUB_USERNAME") {
if let Ok(password) = env::var("GITHUB_TOKEN") {
if let Ok(username) = env::var("USERNAME_FOR_GITHUB") {
if let Ok(password) = env::var("TOKEN_FOR_GITHUB") {
// needs a token with at least public_repo scope
req = req.basic_auth(username, Some(password));
}

View file

@ -181,8 +181,8 @@ async fn get_stars(github_url: &str) -> Option<u32> {
.replace_all(&github_url, "https://api.github.com/repos/$org/$repo")
.to_string();
let mut req = CLIENT.get(&rewritten);
if let Ok(username) = env::var("GITHUB_USERNAME") {
if let Ok(password) = env::var("GITHUB_TOKEN") {
if let Ok(username) = env::var("USERNAME_FOR_GITHUB") {
if let Ok(password) = env::var("TOKEN_FOR_GITHUB") {
// needs a token with at least public_repo scope
req = req.basic_auth(username, Some(password));
}
@ -243,7 +243,7 @@ fn get_url_core(url: String) -> BoxFuture<'static, (String, Result<(), CheckerEr
let mut res = Err(CheckerError::NotTried);
for _ in 0..5u8 {
debug!("Running {}", url);
if env::var("GITHUB_USERNAME").is_ok() && env::var("GITHUB_TOKEN").is_ok() && GITHUB_REPO_REGEX.is_match(&url) {
if env::var("USERNAME_FOR_GITHUB").is_ok() && env::var("TOKEN_FOR_GITHUB").is_ok() && GITHUB_REPO_REGEX.is_match(&url) {
let rewritten = GITHUB_REPO_REGEX.replace_all(&url, "https://api.github.com/repos/$org/$repo");
info!("Replacing {} with {} to workaround rate limits on Github", url, rewritten);
let (_new_url, res) = get_url_core(rewritten.to_string()).await;
@ -254,8 +254,8 @@ fn get_url_core(url: String) -> BoxFuture<'static, (String, Result<(), CheckerEr
.header(header::ACCEPT, "image/svg+xml, text/html, */*;q=0.8");
if GITHUB_API_REGEX.is_match(&url) {
if let Ok(username) = env::var("GITHUB_USERNAME") {
if let Ok(password) = env::var("GITHUB_TOKEN") {
if let Ok(username) = env::var("USERNAME_FOR_GITHUB") {
if let Ok(password) = env::var("TOKEN_FOR_GITHUB") {
// needs a token with at least public_repo scope
info!("Using basic auth for {}", url);
req = req.basic_auth(username, Some(password));