/
create-repo.sh
executable file
·74 lines (66 loc) · 2.73 KB
/
create-repo.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
provider="GitHub"
function create_repo_content {
if [ "$5" == "true" ]
then
gh repo create "$1" --public
else
gh repo create "$1" --private
fi
}
function set_default_branch_and_policies_content_1 {
gh repo edit "$6/$4" --default-branch master > /dev/null
}
function set_default_branch_and_policies_content_2 {
if [ "$7" = "true" ] # $7=true to ensure is a public repo. (Only works on public or Github Pro repos)
then
# Enable branch protection and comment resolution policy all in one. Only avaliable to public (or GH Pro) repositories
if [ "${ENABLE_APPROVE_COUNT}" == "true" ]
then
# Get repoid
repo_id="$(gh api graphql -f query='{repository(owner:"'$6'",name:"'$4'"){id}}' -q .data.repository.id)"
echo "For $i:"
echo -e "${blue}Creating rule to need approval of ${REVIEWER_NBR} people. (enable=${ENABLE_APPROVE_COUNT})"
echo -e "${white}"
echo -e "${blue}Adding comment resolution policy.(enable=${ENABLE_APPROVE_COUNT})"
echo -e "${white}"
gh api graphql -f query='
mutation($repositoryId:ID!,$branch:String!,$requiredReviews:Int!,$enableCommentResolution:Boolean!) {
createBranchProtectionRule(input: {
repositoryId: $repositoryId
pattern: $branch
requiresApprovingReviews: true
requiredApprovingReviewCount: $requiredReviews
requiresConversationResolution: $enableCommentResolution
}) { clientMutationId }
}' -f repositoryId="$repo_id" -f branch="[$i]*" -F requiredReviews="${REVIEWER_NBR}" -F enableCommentResolution="${ENABLE_COMMENT_RESOLUTION}"
fi
if [ "$ENABLE_MERGE_LIMITS" == "true" ]
then
echo -e "${blue}Adding merge limits.(enable=${ENABLE_APPROVE_COUNT})"
echo -e "${white}"
gh repo edit "$6/$4" --enable-rebase-merge="${ALLOW_REBASE_MERGE}" --enable-squash-merge="${ALLOW_SQUASH}"
fi
fi
}
function import_repo_content {
git clone --bare "$1"
source_repo_namegit=${1##*/}
cd "$source_repo_namegit"
git push --mirror https://github.com/$6/$4.git
}
function prepare_push_existing_repo_content {
URL_space_converted="https://github.com/$6/$3.git"
}
function custom_vars_assignment {
organization=""
project=""
ghuser=$(gh auth status 2>&1 | sed -n 2p | awk '{print $7}')
}
function clone_git_project_import {
git clone "https://github.com/$ghuser/$name.git" "$name"
}
function clone_git_project_create {
git clone "https://github.com/$ghuser/$name.git" .
}
source "$(dirname $0)/../common/create-repo.sh"