Skip to content

Commit

Permalink
allowlist of repos (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
akorchyn authored Jun 19, 2024
1 parent 089e874 commit a0f52c2
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 5 deletions.
20 changes: 16 additions & 4 deletions contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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<String>,
}

#[near_bindgen]
impl Contract {
#[init]
pub fn new(sloth: AccountId) -> Self {
pub fn new(sloth: AccountId, allowed_repos: Vec<AllowedRepos>) -> Self {
let mut contract = Self {
sloth,
#[allow(deprecated)]
Expand All @@ -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(),
Expand Down
8 changes: 7 additions & 1 deletion contract/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand Down
78 changes: 78 additions & 0 deletions init.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
]
}

0 comments on commit a0f52c2

Please sign in to comment.