diff --git a/CHANGELOG.md b/CHANGELOG.md index f1c8c5d..8ab8fad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file. +## [v0.4.3](https://codeberg.org/ThetaDev/artifactview/compare/v0.4.2..v0.4.3) - 2024-06-22 + +### 🐛 Bug Fixes + +- 404 error on GitHub comment creation - ([d8c3ab4](https://codeberg.org/ThetaDev/artifactview/commit/d8c3ab4f36727f118b31683db87d287d9945ee14)) + + ## [v0.4.2](https://codeberg.org/ThetaDev/artifactview/compare/v0.4.1..v0.4.2) - 2024-06-22 ### 🐛 Bug Fixes diff --git a/Cargo.lock b/Cargo.lock index 4fe8603..c9226a6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -141,7 +141,7 @@ dependencies = [ [[package]] name = "artifactview" -version = "0.4.2" +version = "0.4.3" dependencies = [ "async_zip", "axum", diff --git a/Cargo.toml b/Cargo.toml index 8490e04..4dc070c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "artifactview" -version = "0.4.2" +version = "0.4.3" edition = "2021" authors = ["ThetaDev "] license = "MIT" diff --git a/README.md b/README.md index 1e7e6cc..c486622 100644 --- a/README.md +++ b/README.md @@ -76,13 +76,19 @@ artifacts. ![Pull request comment](./resources/screenshotPrComment.png) To accomplish that, simply add this step to your CI workflow (after uploading the -artifacts). +artifacts). Note that the workflow URL has to be built differently on GitHub and +Forgejo, so this solution is sadly not cross-forge compatible. ```yaml -- name: 🔗 Artifactview PR comment +- name: 🔗 Artifactview PR comment (Forgejo) if: ${{ always() && github.event_name == 'pull_request' }} run: | curl -SsL --fail-with-body -w "\n" -X POST https://av.thetadev.de/.well-known/api/prComment -H "Content-Type: application/json" --data "{\"url\": \"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_NUMBER\", \"pr\": ${{ github.event.number }}}" + +- name: 🔗 Artifactview PR comment (GitHub) + if: ${{ always() && github.event_name == 'pull_request' }} + run: | + curl -SsL --fail-with-body -w "\n" -X POST https://av.thetadev.de/.well-known/api/prComment -H "Content-Type: application/json" --data "{\"url\": \"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID\", \"pr\": ${{ github.event.number }}}" ``` ## API @@ -254,11 +260,12 @@ Example list: `foo;bar`, example map: `foo=>f1;bar=>b1` ### Access tokens GitHub does not allow downloading artifacts for public repositories for unauthenticated -users. So you need to setup an access token to use Artifactview with GitHub. These are -the permissions that need to be enabled: +users. So you need to setup an access token to use Artifactview with GitHub. -- Repository access: All repositories -- Repository permissions: Pull requests (Read and write) +If you are not using the `prComment` feature, you can use a fine-grained access token +with the "Public repositories (read-only)" permission. If you want to create pull +request comments, you have to use a classic token with the "public_repo" scope enabled +(the fine-grained tokens did not work in my test). Forgejo does not require access tokens to download artifacts on public repositories, so you only need to create a token if you want to use the `prComment`-API. In this case, diff --git a/src/artifact_api.rs b/src/artifact_api.rs index 69c6068..e0edb52 100644 --- a/src/artifact_api.rs +++ b/src/artifact_api.rs @@ -269,6 +269,7 @@ impl ArtifactApi { } } + #[tracing::instrument(level = "error", skip_all)] pub async fn list(&self, query: &RunQuery, cached: bool) -> Result> { let cache_key = query.cache_key(); let fut = async { @@ -290,6 +291,7 @@ impl ArtifactApi { } } + #[tracing::instrument(level = "error", skip_all)] pub async fn fetch(&self, query: &ArtifactQuery) -> Result { if query.is_github() { self.fetch_github(query).await @@ -305,6 +307,7 @@ impl ArtifactApi { } } + #[tracing::instrument(level = "error", skip_all)] pub async fn download(&self, artifact: &Artifact, path: &Path) -> Result<()> { if artifact.expired { return Err(Error::Expired); @@ -416,10 +419,9 @@ impl ArtifactApi { if let Err(e) = resp.error_for_status_ref() { let status = resp.status(); let msg = resp.json::().await.ok(); - Err(Error::HttpClient( - msg.map(|msg| msg.message).unwrap_or(e.to_string()).into(), - status, - )) + let msg_str = msg.map(|msg| msg.message).unwrap_or(e.to_string()).into(); + tracing::error!("API error: {msg_str}"); + Err(Error::HttpClient(msg_str, status)) } else { Ok(resp) } @@ -492,6 +494,7 @@ impl ArtifactApi { .header(header::AUTHORIZATION, format!("token {token}"))) } + #[tracing::instrument(level = "error", skip_all)] pub async fn workflow_run(&self, query: &RunQuery) -> Result { if query.is_github() { self.workflow_run_github(query).await @@ -554,6 +557,7 @@ impl ArtifactApi { Ok(run.into()) } + #[tracing::instrument(level = "error", skip_all)] pub async fn add_comment( &self, query: QueryRef<'_>, @@ -621,8 +625,8 @@ impl ArtifactApi { ) -> Result { if let Some(old_comment_id) = old_comment_id { let url = format!( - "https://api.github.com/repos/{}/{}/issues/{}/comments/{}", - query.user, query.repo, issue_id, old_comment_id + "https://api.github.com/repos/{}/{}/issues/comments/{}", + query.user, query.repo, old_comment_id ); if recreate { Self::send_api_req_empty(self.req_github(Method::DELETE, url)?).await?; @@ -650,6 +654,7 @@ impl ArtifactApi { Ok(new_c.id) } + #[tracing::instrument(level = "error", skip_all)] pub async fn find_comment( &self, query: QueryRef<'_>, @@ -702,6 +707,7 @@ impl ArtifactApi { Ok(None) } + #[tracing::instrument(level = "error", skip_all)] pub async fn get_pr(&self, query: QueryRef<'_>, pr_id: u64) -> Result { let req = if query.is_github() { self.get_github(format!(