Allow running the manager without a token
This is useful for local testing.
This commit is contained in:
parent
96bb2540ba
commit
d4b8241808
|
@ -20,7 +20,7 @@ pub struct Context {
|
|||
/// URL of the repository page
|
||||
pub repo_url: url::Url,
|
||||
/// URL of the repository with authentication information attached
|
||||
pub repo_auth_url: url::Url,
|
||||
pub repo_auth_url: Option<url::Url>,
|
||||
/// Human readable timestamp of this manager run
|
||||
pub timestamp: String,
|
||||
}
|
||||
|
@ -42,13 +42,15 @@ async fn run() -> anyhow::Result<()> {
|
|||
let timestamp = chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string();
|
||||
log::info!("Timestamp of this run is {timestamp}");
|
||||
|
||||
let token =
|
||||
std::env::var("GITHUB_TOKEN").context("Failed accessing GITHUB_TOKEN auth token")?;
|
||||
let token = std::env::var("GITHUB_TOKEN").ok();
|
||||
if token.is_none() {
|
||||
log::warn!("No GITHUB_TOKEN, only performing read-only operations!");
|
||||
}
|
||||
|
||||
let server_url = url::Url::parse(
|
||||
&std::env::var("GITHUB_SERVER_URL")
|
||||
.context("Failed reading GITHUB_SERVER_URL server url")?,
|
||||
)
|
||||
let server_url = url::Url::parse(&std::env::var("GITHUB_SERVER_URL").unwrap_or_else(|_e| {
|
||||
log::warn!("Using FAFO URL as a default GITHUB_SERVER_URL!");
|
||||
"https://git.fa-fo.de".to_string()
|
||||
}))
|
||||
.context("Failed parsing GITHUB_SERVER_URL as a url")?;
|
||||
|
||||
let repo_url = server_url
|
||||
|
@ -57,11 +59,19 @@ async fn run() -> anyhow::Result<()> {
|
|||
meta.issue.repository.owner, meta.issue.repository.name
|
||||
))
|
||||
.unwrap();
|
||||
let mut repo_auth_url = repo_url.clone();
|
||||
repo_auth_url.set_username("forgejo-actions").unwrap();
|
||||
repo_auth_url.set_password(Some(&token)).unwrap();
|
||||
|
||||
let auth = forgejo_api::Auth::Token(&token);
|
||||
let repo_auth_url = token.as_ref().map(|token| {
|
||||
let mut repo_auth_url = repo_url.clone();
|
||||
repo_auth_url.set_username("forgejo-actions").unwrap();
|
||||
repo_auth_url.set_password(Some(&token)).unwrap();
|
||||
repo_auth_url
|
||||
});
|
||||
|
||||
let auth = if let Some(token) = token.as_ref() {
|
||||
forgejo_api::Auth::Token(token)
|
||||
} else {
|
||||
forgejo_api::Auth::None
|
||||
};
|
||||
let forgejo =
|
||||
Forgejo::new(auth, server_url).context("Could not create Forgejo API access object")?;
|
||||
|
||||
|
@ -103,9 +113,14 @@ async fn run() -> anyhow::Result<()> {
|
|||
let rendered_tree = render::render(&ctx, &tree)
|
||||
.await
|
||||
.context("Failed to render the techtree")?;
|
||||
render::publish(&ctx, &rendered_tree)
|
||||
.await
|
||||
.context("Failed to publish rendered tree to git")?;
|
||||
|
||||
if token.is_some() {
|
||||
render::publish(&ctx, &rendered_tree)
|
||||
.await
|
||||
.context("Failed to publish rendered tree to git")?;
|
||||
} else {
|
||||
log::warn!("Skipped publishing the rendered tree.");
|
||||
}
|
||||
|
||||
// Wiki is disabled because the tree is too big for mermaid to handle
|
||||
if false {
|
||||
|
@ -115,6 +130,11 @@ async fn run() -> anyhow::Result<()> {
|
|||
.context("Failed to update the techtree wiki page")?;
|
||||
}
|
||||
|
||||
if token.is_none() {
|
||||
log::warn!("Not running issue updates without token.");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
'issues: for issue in tree.iter_issues() {
|
||||
let subtree = tree.subtree_for_issue(issue).unwrap();
|
||||
let hash = subtree.stable_hash();
|
||||
|
|
|
@ -103,7 +103,12 @@ pub async fn publish(ctx: &crate::Context, rendered: &RenderedTree) -> anyhow::R
|
|||
.arg("push")
|
||||
.arg("--force")
|
||||
.arg("--quiet")
|
||||
.arg(ctx.repo_auth_url.to_string())
|
||||
.arg(
|
||||
ctx.repo_auth_url
|
||||
.as_ref()
|
||||
.expect("cannot publish without authentication token")
|
||||
.to_string(),
|
||||
)
|
||||
.arg("HEAD:refs/heads/render")
|
||||
.status()
|
||||
.context("Failed to push rendered graph to forgejo repository")?;
|
||||
|
|
Loading…
Reference in a new issue