Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/assistant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
types: [opened, synchronize, reopened]

jobs:
insights:
fibbot:
runs-on: ubuntu-latest
permissions:
issues: write
Expand All @@ -18,5 +18,9 @@ jobs:

- name: Run Rust Action
uses: ./
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
pr_number: ${{ github.event.pull_request.number }}
enable_fib: true
max_threshhold: 105
pr_number: ${{ github.event.pull_request.number }}
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ COPY . .
RUN cargo build --release

# Stage 2: Create the runtime image
FROM debian:buster-slim

WORKDIR /app
FROM gcr.io/distroless/cc AS runtime

COPY --from=builder /ticket-assistant/target/release/ticket-assistant /ticket-assistant

Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ For now, it acts as a Fibonacci bot that extracts numbers from a pull request (P
uses: @marcjazz/ticket-assistant@v1
with:
enable_fib: true
max_threshold: 100
max_threshold: 105
pr_number: ${{ github.event.pull_request.number }}
```
**Fixes:**
- "pontential" → "potential"
Expand All @@ -34,10 +35,10 @@ git clone https://github.com/Marcjazz/ticket-assistant.git
#### Build and Run Using Docker
Run the following command:
- `true` enables Fibonacci computation.
- `100` sets the maximum threshold.
- `105` sets the maximum threshold.

```shell
make start true 100
make start true 105
```
**Fixes:**
- Clarified explanation of arguments.
Expand Down
16 changes: 7 additions & 9 deletions src/action.yml → action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ inputs:
max_threshhold:
description: "The maximum number action should compute"
required: true
# repo:
# description: "The repository in the format owner/repo."
# required: true
# github_token:
# description: "GitHub token for API access."
# required: true
pr_number:
description: "The pull request number."
required: true

runs:
using: "docker"
image: "Dockerfile"
args:
- ${{ inputs.pr_number }}
# - ${{ inputs.repo }}
# - ${{ inputs.github_token }}
- ${{ inputs.enable_fib }}
- ${{ inputs.max_threshhold }}
- ${{ inputs.pr_number }}
18 changes: 11 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,19 @@ use utils::{extract_numbers_from_text, parse_bool};
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = env::args().collect::<Vec<String>>();

if args.len() != 3 {
panic!("Missmatch required params, exactly two params are required: enable_fib, max_threshhold")
}

println!("Agrs: {:?}", args);

if args.len() != 4 {
panic!("Missmatch required params, exactly two params are required: enable_fib, max_threshhold and pr_number")
}

let gh_token = env::var("GITHUB_TOKEN").expect("Could not read GITHUB_TOKEN from env.");
let gh_repo =
env::var("GITHUB_REPOSITORY").expect("Could not read GITHUB_REPOSITORY form env.");
let pr_number = env::var("PR_NUMBER").expect("Could not read PR_NUMBER from variable.");

let gh_api = GhAPIClient::new(&gh_token, &gh_repo);

let [_, enable_fib, max_threshhold] = args.as_slice() else {
let [_, enable_fib, max_threshhold, pr_number] = args.as_slice() else {
panic!("Failed to read args");
};

Expand Down Expand Up @@ -61,7 +60,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let comment = if fibonaccies.len() == 0 {
format!("Numberless PR: Nothing to Compute...")
} else {
format!("Fobonaccies: {:?}", fibonaccies)
let mut comment = format!("## Fobonaccies\n");
fibonaccies
.iter()
.for_each(|(val, fibo)| comment.push_str(&format!("> **Fn({val})**: {fibo}\n")));

comment
};

println!("{comment}");
Expand Down
19 changes: 11 additions & 8 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
pub fn extract_numbers_from_text(text: String, max_threshhold: u32) -> Vec<u32> {
let r = text.split(" ");

let mut nums = Vec::new();
for w in r {
let num = w.parse::<u32>();
if let Ok(num) = num {
if num <= max_threshhold {
nums.push(num);
let mut nums = vec![];
let mut num_string = String::new();
for char in text.chars() {
if char.is_digit(10) {
num_string.push(char);
} else {
if let Ok(num) = num_string.parse::<u32>() {
if num <= max_threshhold && !nums.contains(&num) {
nums.push(num);
num_string = String::new()
}
}
}
}
Expand Down