Skip to content

Commit

Permalink
REFACTOR to MONOLITH
Browse files Browse the repository at this point in the history
  • Loading branch information
ffakenz committed May 6, 2024
1 parent 07aeaac commit b48dcad
Show file tree
Hide file tree
Showing 25 changed files with 196 additions and 226 deletions.
57 changes: 21 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[workspace]
members = [
"provider/github",
"bounty",
"backend"
]
resolver = "2"
39 changes: 18 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ build: node_modules
--with-cycles 1_000_000_000_000 \
--specified-id n5wcd-faaaa-aaaar-qaaea-cai \
icrc1_index
dfx canister create github
dfx canister create bounty
dfx canister create backend
dfx build

.PHONY: install
Expand All @@ -36,17 +35,15 @@ install: build
dfx canister install identity --argument '(null)' --mode reinstall --yes
./make/install_ledger.sh
./make/install_ledger_index.sh
dfx canister install github --mode reinstall --yes
./make/install_bounty.sh
./make/install_backend.sh

.PHONY: upgrade
.SILENT: upgrade
upgrade: build
dfx canister install identity --argument '(null)' --mode=upgrade
dfx canister install icrc1_ledger --mode=upgrade
dfx canister install icrc1_index --argument '(null)' --mode=upgrade
dfx canister install github --mode=upgrade
dfx canister install bounty --mode=upgrade
dfx canister install backend --mode=upgrade

.PHONY: clean
.SILENT: clean
Expand All @@ -59,54 +56,54 @@ clean:
.PHONY: test-1
.SILENT: test-1
test-1: install
# Call the github canister to get the GitHub issue and capture the output
@echo "Calling get_issue on github canister..."
# Call the backend canister to get the GitHub issue and capture the output
@echo "Calling get_issue on backend canister..."
@TMP_FILE=$$(mktemp); \
dfx canister call github get_issue '("${GITHUB_TOKEN}")' > $$TMP_FILE; \
dfx canister call backend get_issue '("${GITHUB_TOKEN}")' > $$TMP_FILE; \
echo "get_issue response:"; \
cat $$TMP_FILE; \
rm -f $$TMP_FILE

.PHONY: test-2
.SILENT: test-2
test-2: install
# Call the github canister to get the GitHub PR that close some issue and capture the output
@echo "Calling get_fixed_by on github canister..."
# Call the backend canister to get the GitHub PR that close some issue and capture the output
@echo "Calling get_fixed_by on backend canister..."
@TMP_FILE=$$(mktemp); \
dfx canister call github get_fixed_by '("${GITHUB_TOKEN}")' > $$TMP_FILE; \
dfx canister call backend get_fixed_by '("${GITHUB_TOKEN}")' > $$TMP_FILE; \
echo "get_fixed_by response:"; \
cat $$TMP_FILE; \
rm -f $$TMP_FILE

.PHONY: test-3
.SILENT: test-3
test-3: install
# Call the github canister to get the GitHub PR merge status and capture the output
@echo "Calling get_is_merged on github canister..."
# Call the backend canister to get the GitHub PR merge status and capture the output
@echo "Calling get_is_merged on backend canister..."
@TMP_FILE=$$(mktemp); \
dfx canister call github get_is_merged '("${GITHUB_TOKEN}")' > $$TMP_FILE; \
dfx canister call backend get_is_merged '("${GITHUB_TOKEN}")' > $$TMP_FILE; \
echo "get_is_merged response:"; \
cat $$TMP_FILE; \
rm -f $$TMP_FILE

.PHONY: test-4
.SILENT: test-4
test-4: install
# Call the github canister to get the GitHub closing PR details and capture the output
@echo "Calling get_merged_details on github canister..."
# Call the backend canister to get the GitHub closing PR details and capture the output
@echo "Calling get_merged_details on backend canister..."
@TMP_FILE=$$(mktemp); \
dfx canister call github get_merged_details '("${GITHUB_TOKEN}")' > $$TMP_FILE; \
dfx canister call backend get_merged_details '("${GITHUB_TOKEN}")' > $$TMP_FILE; \
echo "get_merged_details response:"; \
cat $$TMP_FILE; \
rm -f $$TMP_FILE

.PHONY: test-a
.SILENT: test-a
test-a: install
# Call the bounty canister for healthcheck and capture the output
@echo "Calling healthcheck on bounty canister..."
# Call the backend canister for healthcheck and capture the output
@echo "Calling healthcheck on backend canister..."
@TMP_FILE=$$(mktemp); \
dfx canister call bounty healthcheck > $$TMP_FILE; \
dfx canister call backend healthcheck > $$TMP_FILE; \
echo "healthcheck response:"; \
cat $$TMP_FILE; \
rm -f $$TMP_FILE
Expand Down
4 changes: 2 additions & 2 deletions bounty/Cargo.toml → backend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "bounty"
name = "backend"
version = "0.1.0"
edition = "2021"

Expand All @@ -21,4 +21,4 @@ num-bigint = "0.4.4"
num-traits = "0.2.18"
futures = "0.3.30"
async-trait = "0.1.8"
github = { path = "../provider/github", version = "0.1.0"}
regex = "1.5.4"
26 changes: 25 additions & 1 deletion provider/github/github.did → backend/backend.did
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// GitHub Service

type Issue = record {
state: opt text;
login: opt text;
Expand Down Expand Up @@ -32,10 +34,32 @@ type User = record {

type GithubToken = text;

service : {
// Bounty Service

type Contributor = record {
address: principal;
crypto_address: text;
};

type DepositReceipt = variant {
Err: DepositErr;
Ok: nat;
};

type DepositErr = variant {
TransferFailure : record { reason : text };
};

service : (authority: principal, github_issue_id: int32) -> {
// Bounty Service
"healthcheck": () -> (text);
"accept": (Contributor, github_pr_id: int32) -> ();
"deposit": () -> (DepositReceipt);
// GitHub Service
"get_issue": (GithubToken) -> (Issue);
"get_fixed_by": (GithubToken) -> (text);
"get_is_merged": (GithubToken) -> (text);
"get_merged_details": (GithubToken) -> (PrDetailsResponse);
}


Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn accept_impl(contributor: Contributor, github_pr_id: i32) -> () {
#[cfg(test)]
mod test_accept {
use super::*;
use crate::api::init::init_impl;
use crate::bounty::api::init::init_impl;
use candid::Principal;

#[test]
Expand Down
12 changes: 6 additions & 6 deletions bounty/src/api/claim.rs → backend/src/bounty/api/claim.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::api::state::BOUNTY_STATE;
use crate::bounty::api::state::{BOUNTY_STATE, Contributor};
use candid::{CandidType, Principal};
use serde::{Deserialize, Serialize};
use super::state::Contributor;

use github::{api::{get_issue::IssueResponse, get_merged_details::PrDetailsResponse}, client::IGithubClient};
use crate::provider::github::api::{get_issue::IssueResponse, get_merged_details::PrDetailsResponse};
use crate::provider::github::client::IGithubClient;

#[derive(Debug, Serialize, Deserialize, CandidType)]
pub enum ClaimError {
Expand Down Expand Up @@ -55,9 +55,9 @@ pub async fn claim_impl(

#[cfg(test)]
mod test_claim {
use crate::api::accept::accept_impl;
use crate::api::init::init_impl;
use crate::api::state::{Contributor, BOUNTY_STATE};
use crate::bounty::api::accept::accept_impl;
use crate::bounty::api::init::init_impl;
use crate::bounty::api::state::{Contributor, BOUNTY_STATE};
use candid::Principal;
use futures::executor::block_on;

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
109 changes: 109 additions & 0 deletions backend/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
use candid::Principal;

// GITHUB SERVICE
pub mod provider {
pub mod github {
pub mod api {
pub mod get_fixed_by;
pub mod get_is_merged;
pub mod get_issue;
pub mod get_merged_details;
}
pub mod client;
pub mod utils;
}
}
use provider::github::api::get_issue::IssueResponse;
use provider::github::api::get_merged_details::PrDetailsResponse;
use provider::github::client::{GithubClient, IGithubClient};

// BOUNTY SERVICE
pub mod bounty {
pub mod api {
pub mod accept;
pub mod claim;
pub mod deposit;
pub mod icrc1;
pub mod init;
pub mod state;
}
}

use bounty::api::accept::accept_impl;
use bounty::api::init::init_impl;
use bounty::api::deposit::{deposit_impl, DepositReceipt};
use bounty::api::state::Contributor;

// GITHUB SERVICE
#[ic_cdk::update]
async fn get_issue(github_token: String) -> IssueResponse {
let owner = "input-output-hk".to_string();
let repo = "hydra".to_string();
let issue_nbr = 1218;
let client = GithubClient {
owner,
repo,
github_token,
};
return client.get_issue(issue_nbr).await;
}

#[ic_cdk::update]
async fn get_fixed_by(github_token: String) -> String {
let owner = "input-output-hk".to_string();
let repo = "hydra".to_string();
let issue_nbr = 1370;
let client = GithubClient {
owner,
repo,
github_token,
};
return client.get_fixed_by(issue_nbr).await;
}

#[ic_cdk::update]
async fn get_is_merged(github_token: String) -> String {
let owner = "input-output-hk".to_string();
let repo = "hydra".to_string();
let pr_nbr = 1266;
let client = GithubClient {
owner,
repo,
github_token,
};
return client.get_is_merged(pr_nbr).await;
}

#[ic_cdk::update]
async fn get_merged_details(github_token: String) -> PrDetailsResponse {
let owner = "input-output-hk".to_string();
let repo = "hydra".to_string();
let pr_nbr = 1266;
let client = GithubClient {
owner,
repo,
github_token,
};
return client.get_merged_details(pr_nbr).await;
}

// BOUNTY SERVICE
#[ic_cdk::init]
fn init(authority: Principal, github_issue_id: i32) -> () {
init_impl(authority, github_issue_id);
}

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

#[ic_cdk::update]
async fn deposit() -> DepositReceipt {
return deposit_impl().await;
}

#[ic_cdk::update]
async fn healthcheck() -> String {
return "OK".to_string();
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit b48dcad

Please sign in to comment.