Skip to content

Commit

Permalink
Add pr nbr as part of accept
Browse files Browse the repository at this point in the history
  • Loading branch information
ffakenz committed May 3, 2024
1 parent 0154503 commit 33cd2cc
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
4 changes: 2 additions & 2 deletions bounty/bounty.did
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ type DepositErr = variant {
TransferFailure : record { reason : text };
};

service : (principal, int32) -> {
service : (authority: principal, github_issue_id: int32) -> {
"healthcheck": () -> (text);
"accept": (Contributor) -> ();
"accept": (Contributor, github_pr_id: int32) -> ();
"deposit": () -> (DepositReceipt);
}

16 changes: 10 additions & 6 deletions bounty/src/api/accept.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::state::{Contributor, BOUNTY_STATE};

pub fn accept_impl(contributor: Contributor) -> () {
pub fn accept_impl(contributor: Contributor, github_pr_id: i32) -> () {
BOUNTY_STATE.with(|state| {
if let Some(ref mut bounty_canister) = *state.borrow_mut() {
// Add the contributor to the interested contributors list
bounty_canister.interested_contributors.push(contributor);
bounty_canister.interested_contributors.insert(github_pr_id, contributor);
}
});
}
Expand Down Expand Up @@ -32,10 +32,14 @@ mod test_accept {
let contributor =
Principal::from_text("t2y5w-qp34w-qixaj-s67wp-syrei-5yqse-xbed6-z5nsd-fszmf-izgt2-lqe")
.unwrap();
accept_impl(Contributor {
address: contributor,
crypto_address: "contributor_address".to_string(),
});
let github_pr_id = 88;
accept_impl(
Contributor {
address: contributor,
crypto_address: "contributor_address".to_string(),
},
github_pr_id,
);
BOUNTY_STATE.with(|state| {
let bounty_canister = state.borrow();
if let Some(ref bounty_canister) = *bounty_canister {
Expand Down
4 changes: 3 additions & 1 deletion bounty/src/api/init.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::HashMap;

use super::state::{BountyState, BOUNTY_STATE};
use candid::Principal;

Expand All @@ -6,7 +8,7 @@ pub fn init_impl(authority: Principal, github_issue_id: i32) -> () {
*state.borrow_mut() = Some(BountyState {
authority,
github_issue_id,
interested_contributors: Vec::new(),
interested_contributors: HashMap::new(),
claimed: false,
});
});
Expand Down
9 changes: 7 additions & 2 deletions bounty/src/api/state.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
use std::collections::HashMap;

use candid::{CandidType, Principal};
use serde::{Deserialize, Serialize};

type IssueId = i32;
type PullRequestId = i32;

#[derive(Debug, Serialize, Deserialize, CandidType)]
pub struct BountyState {
pub authority: Principal,
pub github_issue_id: i32,
pub interested_contributors: Vec<Contributor>,
pub github_issue_id: IssueId,
pub interested_contributors: HashMap<PullRequestId, Contributor>,
pub claimed: bool,
}

Expand Down
4 changes: 2 additions & 2 deletions bounty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ fn init(authority: Principal, github_issue_id: i32) -> () {
}

#[ic_cdk::update]
fn accept(contributor: Contributor) -> () {
accept_impl(contributor);
fn accept(contributor: Contributor, github_pr_id: i32) -> () {
accept_impl(contributor, github_pr_id);
}

#[ic_cdk::update]
Expand Down

0 comments on commit 33cd2cc

Please sign in to comment.