Skip to content

Commit 4567bd1

Browse files
committed
wip: init commit of clippy annotation reporter
1 parent 18c8773 commit 4567bd1

File tree

5 files changed

+137
-1
lines changed

5 files changed

+137
-1
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "clippy-annotation-reporter"
3+
rust-version.workspace = true
4+
edition.workspace = true
5+
license.workspace = true
6+
version = "0.1.0"
7+
8+
[dependencies]
9+
clap = { version = "4.3", features = ["derive"] }
10+
octocrab = "0.28"
11+
anyhow = "1.0"
12+
regex = "1.9"
13+
tokio = { version = "1", features = ["full"] }
14+
serde = { version = "1.0", features = ["derive"] }
15+
serde_json = "1.0"
16+
log = "0.4"
17+
env_logger = "0.10"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: 'Clippy Annotation Reporter'
2+
description: 'Reports changes in Clippy allow annotations'
3+
author: 'Datadog'
4+
5+
inputs:
6+
github-token:
7+
description: 'GitHub token for PR comment access'
8+
required: true
9+
default: ${{ github.token }}
10+
allow-annotation-rules:
11+
description: 'Comma-separated list of clippy rules to track'
12+
required: false
13+
default: 'unwrap_used,expect_used,todo,unimplemented,panic,unreachable'
14+
15+
runs:
16+
using: 'composite'
17+
steps:
18+
- name: Set up Rust
19+
uses: dtolnay/rust-toolchain@stable
20+
with:
21+
toolchain: stable
22+
23+
- name: Build annotation reporter
24+
shell: bash
25+
run: |
26+
cd ${{ github.action_path }}
27+
cargo build --release
28+
29+
- name: Run annotation reporter
30+
shell: bash
31+
run: |
32+
${{ github.action_path }}/target/release/clippy-annotation-reporter \
33+
--token "${{ inputs.github-token }}" \
34+
--rules "${{ inputs.panic-rules }}" \
35+
--repo "${{ github.repository }}" \
36+
--pr "${{ github.event.pull_request.number }}"
37+
env:
38+
GITHUB_TOKEN: ${{ inputs.github-token }}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
use anyhow::{Context, Result};
2+
use octocrab::Octocrab;
3+
use std::env;
4+
5+
#[tokio::main]
6+
async fn main() -> Result<()> {
7+
println!("Hello World from clippy-annotation-checker!");
8+
println!("Action is running successfully!");
9+
10+
// Get required environment variables
11+
let github_token = env::var("GITHUB_TOKEN")
12+
.context("GITHUB_TOKEN environment variable not set")?;
13+
14+
let github_repository = env::var("GITHUB_REPOSITORY")
15+
.context("GITHUB_REPOSITORY environment variable not set")?;
16+
17+
let event_path = env::var("GITHUB_EVENT_PATH")
18+
.context("GITHUB_EVENT_PATH environment variable not set")?;
19+
20+
// Parse event data to get PR number
21+
let event_data = std::fs::read_to_string(event_path)
22+
.context("Failed to read event file")?;
23+
24+
let event_json: serde_json::Value = serde_json::from_str(&event_data)
25+
.context("Failed to parse event JSON")?;
26+
27+
let pr_number = event_json["pull_request"]["number"]
28+
.as_u64()
29+
.context("Could not find PR number in event data")?;
30+
31+
// Split repository into owner and name
32+
let repo_parts: Vec<&str> = github_repository.split('/').collect();
33+
if repo_parts.len() != 2 {
34+
anyhow::bail!("Invalid repository format: {}", github_repository);
35+
}
36+
37+
let owner = repo_parts[0];
38+
let repo = repo_parts[1];
39+
40+
println!("Posting Hello World comment to PR #{} in {}/{}", pr_number, owner, repo);
41+
42+
// Initialize GitHub client
43+
let octocrab = Octocrab::builder()
44+
.personal_token(github_token)
45+
.build()
46+
.context("Failed to build GitHub client")?;
47+
48+
// Post a simple comment
49+
octocrab
50+
.issues(owner, repo)
51+
.create_comment(pr_number, "## Hello World from clippy-annotation-checker!\n\nThis action is running successfully and can post comments to PRs.")
52+
.await
53+
.context("Failed to post comment")?;
54+
55+
println!("Comment posted successfully!");
56+
57+
Ok(())
58+
}

.github/workflows/clippy-annotation-reporter.yml

Whitespace-only changes.

.github/workflows/lint.yml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,30 @@ jobs:
4949
fi
5050
# shellcheck disable=SC2046
5151
cargo clippy --workspace --all-targets --all-features -- -D warnings $([ ${{ matrix.rust_version }} = 1.78.0 ] || [ ${{ matrix.rust_version }} = stable ] && echo -Aunknown-lints -Ainvalid_reference_casting -Aclippy::redundant-closure-call)
52-
52+
clippy-annotation-reporter:
53+
runs-on: ubuntu-latest
54+
steps:
55+
- name: Checkout sources
56+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
57+
- name: Set up Rust
58+
uses: dtolnay/rust-toolchain@stable
59+
with:
60+
toolchain: stable
61+
- name: Build annotation reporter
62+
shell: bash
63+
run: |
64+
cd ${{ github.action_path }}
65+
cargo build --release
66+
- name: Run annotation reporter
67+
shell: bash
68+
run: |
69+
${{ github.action_path }}/target/release/clippy-annotation-reporter \
70+
--token "${{ secrets.GITHUB_TOKEN }}" \
71+
--rules "unwrap_used,expect_used,todo,unimplemented,panic,unreachable" \
72+
--repo "${{ github.repository }}" \
73+
--pr "${{ github.event.pull_request.number }}"
74+
env:
75+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5376
licensecheck:
5477
runs-on: ubuntu-latest
5578
name: "Presence of licence headers"

0 commit comments

Comments
 (0)