Skip to content

Commit

Permalink
Output error messages when github returns them. Also show the full bo…
Browse files Browse the repository at this point in the history
…dy when possible.
  • Loading branch information
orf committed Mar 4, 2023
1 parent 5577a3b commit 7e31bcb
Show file tree
Hide file tree
Showing 8 changed files with 32,510 additions and 12,808 deletions.
20 changes: 10 additions & 10 deletions example_workspace/workspace-github.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[[provider]]
provider = "github"
name = "django"
path = "github"
env_var = "GITHUB_TOKEN"
skip_forks = false
exclude = [
"djangobench$",
"dsf-.*"
]
#[[provider]]
#provider = "github"
#name = "django"
#path = "github"
#env_var = "GITHUB_TOKEN"
#skip_forks = false
#exclude = [
# "djangobench$",
# "dsf-.*"
#]
129 changes: 129 additions & 0 deletions example_workspace/workspace-lock.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,132 @@ url = "[email protected]:tom6/test-empty-project.git"
path = "gitlab/tom6/test-lfs"
url = "[email protected]:tom6/test-lfs.git"
branch = "master"

[[repo]]
path = "omgdgsdgsdsgdgssdggds/foobar/Awesome-Geospatial"
url = "[email protected]:foobar/Awesome-Geospatial.git"
upstream = "[email protected]:sacridini/Awesome-Geospatial.git"
branch = "master"

[[repo]]
path = "omgdgsdgsdsgdgssdggds/foobar/VictoriaMetrics"
url = "[email protected]:foobar/VictoriaMetrics.git"
upstream = "[email protected]:VictoriaMetrics/VictoriaMetrics.git"
branch = "master"

[[repo]]
path = "omgdgsdgsdsgdgssdggds/foobar/algc"
url = "[email protected]:foobar/algc.git"
upstream = "[email protected]:a1exwang/algc.git"
branch = "master"

[[repo]]
path = "omgdgsdgsdsgdgssdggds/foobar/algo"
url = "[email protected]:foobar/algo.git"
upstream = "[email protected]:hoanhan101/algo.git"
branch = "master"

[[repo]]
path = "omgdgsdgsdsgdgssdggds/foobar/centos-repo"
url = "[email protected]:foobar/centos-repo.git"
upstream = "[email protected]:cloudrouter/centos-repo.git"
branch = "master"

[[repo]]
path = "omgdgsdgsdsgdgssdggds/foobar/concurrent-persistent-datastructure"
url = "[email protected]:foobar/concurrent-persistent-datastructure.git"
upstream = "[email protected]:aajayssingh/concurrent-persistent-datastructure.git"
branch = "master"

[[repo]]
path = "omgdgsdgsdsgdgssdggds/foobar/docs.influxdata.com"
url = "[email protected]:foobar/docs.influxdata.com.git"
upstream = "[email protected]:influxdata/docs.influxdata.com-ARCHIVE.git"
branch = "master"

[[repo]]
path = "omgdgsdgsdsgdgssdggds/foobar/fast17"
url = "[email protected]:foobar/fast17.git"
upstream = "[email protected]:andyrudoff/fast17.git"
branch = "master"

[[repo]]
path = "omgdgsdgsdsgdgssdggds/foobar/fucking-algorithm"
url = "[email protected]:foobar/fucking-algorithm.git"
upstream = "[email protected]:labuladong/fucking-algorithm.git"
branch = "master"

[[repo]]
path = "omgdgsdgsdsgdgssdggds/foobar/go-profiler-notes"
url = "[email protected]:foobar/go-profiler-notes.git"
upstream = "[email protected]:DataDog/go-profiler-notes.git"
branch = "main"

[[repo]]
path = "omgdgsdgsdsgdgssdggds/foobar/influxdb"
url = "[email protected]:foobar/influxdb.git"
upstream = "[email protected]:influxdata/influxdb.git"
branch = "1.7"

[[repo]]
path = "omgdgsdgsdsgdgssdggds/foobar/influxdb1-client"
url = "[email protected]:foobar/influxdb1-client.git"
upstream = "[email protected]:influxdata/influxdb1-client.git"
branch = "master"

[[repo]]
path = "omgdgsdgsdsgdgssdggds/foobar/infobright"
url = "[email protected]:foobar/infobright.git"
upstream = "[email protected]:magiczqw/infobright.git"
branch = "master"

[[repo]]
path = "omgdgsdgsdsgdgssdggds/foobar/infobright-4.0.7"
url = "[email protected]:foobar/infobright-4.0.7.git"
upstream = "[email protected]:guanlisheng/infobright-4.0.7.git"
branch = "master"

[[repo]]
path = "omgdgsdgsdsgdgssdggds/foobar/infobright-core"
url = "[email protected]:foobar/infobright-core.git"
upstream = "[email protected]:EidosMedia/infobright-core.git"
branch = "master"

[[repo]]
path = "omgdgsdgsdsgdgssdggds/foobar/misc"
url = "[email protected]:foobar/misc.git"
branch = "master"

[[repo]]
path = "omgdgsdgsdsgdgssdggds/foobar/mysql-server"
url = "[email protected]:foobar/mysql-server.git"
upstream = "[email protected]:mysql/mysql-server.git"
branch = "c++17"

[[repo]]
path = "omgdgsdgsdsgdgssdggds/foobar/optpls"
url = "[email protected]:foobar/optpls.git"
branch = "master"

[[repo]]
path = "omgdgsdgsdsgdgssdggds/foobar/stonedb"
url = "[email protected]:foobar/stonedb.git"
upstream = "[email protected]:stoneatom/stonedb.git"
branch = "stonedb-5.6"

[[repo]]
path = "omgdgsdgsdsgdgssdggds/foobar/stx-btree"
url = "[email protected]:foobar/stx-btree.git"
upstream = "[email protected]:bingmann/stx-btree.git"
branch = "master"

[[repo]]
path = "omgdgsdgsdsgdgssdggds/foobar/tmp"
url = "[email protected]:foobar/tmp.git"
branch = "master"

[[repo]]
path = "omgdgsdgsdsgdgssdggds/foobar/tsbs"
url = "[email protected]:foobar/tsbs.git"
upstream = "[email protected]:timescale/tsbs.git"
branch = "master"
20 changes: 15 additions & 5 deletions example_workspace/workspace.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
#[[provider]]
#provider = "gitlab"
#name = "tom6"
#url = "https://gitlab.com"
#path = "gitlab"
#env_var = "GITLAB_TOKEN"
#exclude = []

[[provider]]
provider = "gitlab"
name = "tom6"
url = "https://gitlab.com"
path = "gitlab"
env_var = "GITLAB_TOKEN"
provider = "github"
name = "omgdgsdgsdsgdgssdggds"
path = "github"
env_var = "GITHUB_TOKEN"
skip_forks = false
exclude = []
url = "https://api.github.com/graphql"
File renamed without changes.
4 changes: 4 additions & 0 deletions scripts/update_graphql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

graphql-client introspect-schema https://gitlab.com/api/graphql > src/providers/graphql/gitlab/schema.json
wget https://docs.github.com/public/schema.docs.graphql -O src/providers/graphql/github/schema.graphql
38 changes: 32 additions & 6 deletions src/providers/github.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::providers::{create_exclude_regex_set, Provider, APP_USER_AGENT};
use crate::repository::Repository;
use anyhow::Context;
use anyhow::{bail, Context};
use console::style;
use graphql_client::{GraphQLQuery, Response};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -166,14 +166,40 @@ impl Provider for GithubProvider {
let res = agent
.post(&self.url)
.set("Authorization", format!("Bearer {}", github_token).as_str())
.send_json(json!(&q))?;
let response_data: Response<repositories::ResponseData> =
serde_json::from_value(res.into_json()?)?;
.send_json(json!(&q));

let res = match res {
Ok(response) => response,
Err(ureq::Error::Status(status, response)) => match response.into_string() {
Ok(resp) => {
bail!("Got status code {status}. Body: {resp}")
}
Err(e) => {
bail!("Got status code {status}. Error reading body: {e}")
}
},
Err(e) => return Err(e.into()),
};

let body = res.into_string()?;
let response_data: Response<repositories::ResponseData> = serde_json::from_str(&body)?;

if let Some(errors) = response_data.errors {
let total_errors = errors.len();
let combined_errors: Vec<_> = errors.into_iter().map(|e| e.message).collect();
let combined_message = combined_errors.join("\n");
bail!(
"Received {} errors. Errors:\n{}",
total_errors,
combined_message
);
}

let response_repositories = response_data
.data
.unwrap_or_else(|| panic!("Invalid response from GitHub for user {}", self.name))
.with_context(|| format!("Invalid response from GitHub: {}", body))?
.repository_owner
.unwrap_or_else(|| panic!("Invalid response from GitHub for user {}", self.name))
.with_context(|| format!("Invalid response from GitHub: {}", body))?
.repositories;

repositories.extend(
Expand Down
Loading

0 comments on commit 7e31bcb

Please sign in to comment.