diff --git a/contract/src/lib.rs b/contract/src/lib.rs index c1c03bc..93b3d82 100644 --- a/contract/src/lib.rs +++ b/contract/src/lib.rs @@ -3,8 +3,9 @@ use near_sdk::store::UnorderedMap; use near_sdk::{ borsh::{BorshDeserialize, BorshSerialize}, require, + serde::{Deserialize, Serialize}, store::{LookupSet, Vector}, - Timestamp, + NearSchema, Timestamp, }; use near_sdk::{env, near_bindgen, AccountId, PanicOnDefault}; use shared::{ @@ -47,10 +48,18 @@ pub struct Contract { user_streaks: UnorderedMap<(GithubHandle, StreakId), VersionedStreakUserData>, } +#[derive(Serialize, Deserialize, BorshDeserialize, BorshSerialize, NearSchema)] +#[borsh(crate = "near_sdk::borsh")] +#[serde(crate = "near_sdk::serde")] +pub struct AllowedRepos { + organization: String, + repos: Vec, +} + #[near_bindgen] impl Contract { #[init] - pub fn new(sloth: AccountId) -> Self { + pub fn new(sloth: AccountId, allowed_repos: Vec) -> Self { let mut contract = Self { sloth, #[allow(deprecated)] @@ -69,8 +78,11 @@ impl Contract { user_streaks: UnorderedMap::new(storage::StorageKey::UserStreaks), }; - contract.allow_organization("NEAR-DevHub".to_owned()); - contract.allow_organization("akorchyn".to_owned()); + for org in allowed_repos { + for repo in org.repos { + contract.include_repo(org.organization.clone(), repo) + } + } contract.create_streak( "Weekly PR".to_owned(), diff --git a/contract/src/tests.rs b/contract/src/tests.rs index eb83d0a..e56afb0 100644 --- a/contract/src/tests.rs +++ b/contract/src/tests.rs @@ -26,7 +26,13 @@ impl ContractExt { context.predecessor_account_id = admin(); testing_env!(context.clone()); - let contract = Contract::new(admin()); + let contract = Contract::new( + admin(), + vec![AllowedRepos { + organization: "NEAR-DevHub".to_owned(), + repos: vec!["devbot".to_owned()], + }], + ); Self { contract, context } } diff --git a/init.json b/init.json new file mode 100644 index 0000000..86955a9 --- /dev/null +++ b/init.json @@ -0,0 +1,78 @@ +{ + "sloth": "race-of-sloths.testnet", + "allowed_repos": [ + { + "organization": "near", + "repos": [ + "nearcore", + "fast-auth-signer", + "near-sdk-rs", + "cargo-near", + "wallet-selector", + "near-public-lakehouse", + "mpc", + "near-api-js", + "cargo-near-new-project-template", + "docs", + "NEPs", + "near-jsonrpc-client-rs", + "near-sandbox", + "queryapi", + "near-cli-rs", + "near-fastauth-wallet", + "near-lake-indexer", + "near-workspaces-rs", + "near-workspaces-js", + "near-lake-framework-rs", + "near-lake-framework-js", + "chainsig-lib", + "node-docs", + "read-rpc", + "near-social-db-sdk", + "near-sdk-js", + "borsh-rs", + "borsh-js", + "pagoda-relayer-rs", + "multichain-gas-station-contract", + "near-sdk-js-template-project", + "create-near-app", + "near-sdk-contract-tools" + ] + }, + { + "organization": "NEAR-DevHub", + "repos": [ + "neardevhub-contract", + "neardevhub-bos", + "race-of-sloths", + "neardevhub-treasury-dashboard", + "race-of-sloths-website" + ] + }, + { + "organization": "bos-cli-rs", + "repos": [ + "near-socialdb-client-rs", + "bos-cli-rs" + ] + }, + { + "organization": "NearSocial", + "repos": [ + "viewer", + "VM", + "social-db" + ] + }, + { + "organization": "fastnear", + "repos": [ + "redis-node", + "fast-near", + "explorer-api", + "clickhouse-provider", + "neardata-server" + ] + } + ] +}