Skip to content
Snippets Groups Projects
Unverified Commit ca9c7291 authored by poly000's avatar poly000
Browse files

initial commit

parents
No related branches found
No related tags found
No related merge requests found
LICENSE 0 → 100644
The MIT License (MIT)
Copyright (c) 2023 poly000
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.
apply.sh 0 → 100755
#!/usr/bin/env bash
if [ $# != 4 ]
then
cat <<-EOF
Usage:
pat=... $0 {org_url} {proj_name} {repo_name} {branch}
Examples:
pat=... $0 https://dev.azure.com/azvse aztest aztest bensl/tmpbuild/1201
EOF
exit 1
fi
if ! [[ ${pat} ]]
then
echo please set pat as your personalAccessToken
exit 2
fi
export org_url=$1
export proj_name=$2
export repo_name=$3
export branch=$4
function get_repo_id {
az repos list --org "${org_url}" \
--proj aztest | \
jq -r ".[] | select(.name == \"${repo_name}\") | .id"
}
# https://unix.stackexchange.com/a/383166
# export function to subshells for bash
typeset -fx get_repo_id
function print_policy_list() {
az repos policy list \
--branch ${branch} \
--repository-id "${repo_id}" \
--org "${org_url}" \
--project "${proj_name}"
}
function setup_build_policy() {
curl -X POST "${org_url}"/"${proj_name}"/_apis/policy/configurations?api-version=7.2-preview.1 \
-H "Authorization: Basic "$(echo -n :${pat} | base64) \
-H 'Content-Type: application/json' \
-d \
'{
"isEnabled": true,
"isBlocking": false,
"type": {
"id": "fa4e907d-c16b-4a4c-9dfa-4906e5d171dd"
},
"settings": {
"allowDownvotes": false,
"blockLastPusherVote": true,
"creatorVoteCounts": false,
"minimumApproverCount": 2,
"requireVoteOnEachIteration": true,
"requireVoteOnLastIteration": true,
"resetOnSourcePush": false,
"resetRejectionsOnSourcePush": false,
"scope": [
{
"repositoryId": "'${repo_id}'",
"refName": "refs/heads/'${branch}'",
"matchKind": "exact"
}
]
}
}'
}
function setup_build_validation() {
# TODO: get build definition id
build_definition_id=2
az repos policy build create \
--blocking true \
--branch ${branch} \
--build-definition-id ${build_definition_id}\
--display-name \
--enabled true \
--manual-queue-only false \
--queue-on-source-update-only true \
--valid-duration 720 \
--repository-id ${repo_id} \
--org ${org_url} \
--project ${proj_name} \
}
export repo_id=$( get_repo_id )
print_policy_list
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment