mirror of
https://code.forgejo.org/actions/cascading-pr
synced 2025-03-15 14:54:40 +01:00
cascading-pr.sh login both repos
This commit is contained in:
parent
007e34c709
commit
71281446ea
7 changed files with 52 additions and 16 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,6 +3,7 @@ forgejo-runner-pid
|
|||
forgejo-runner-token
|
||||
forgejo-runner.clientpid
|
||||
forgejo-runner.log
|
||||
forgejo-runner-home
|
||||
forgejo-token
|
||||
forgejo-api
|
||||
forgejo-header
|
||||
|
|
|
@ -12,7 +12,9 @@ forgejo-runner.sh teardown
|
|||
forgejo.sh teardown
|
||||
forgejo.sh setup root admin1234 codeberg.org/forgejo/forgejo 1.21
|
||||
forgejo-runner.sh setup
|
||||
firefox http://$(cat forgejo-ip):3000
|
||||
url=http://$(cat forgejo-ip):3000
|
||||
firefox $url
|
||||
tests/run.sh --debug
|
||||
tests/run.sh --debug create_pull_request
|
||||
cascading-pr.sh --debug --origin-url "$url" --origin-repo "user1/originrepo" --origin-token "$(cat /tmp/cascading-pr/user1/token)" --destination-url "$url" --destination-repo "user2/destinationrepo" --destination-token "$(cat /tmp/cascading-pr/user2/token)" --destination-branch "main" --update "upgraded"
|
||||
```
|
||||
|
|
|
@ -60,5 +60,5 @@ runs:
|
|||
--destination-repo "${{ inputs.destination-repo }}" \
|
||||
--destination-token "${{ inputs.destination-token }}" \
|
||||
--destination-branch "${{ inputs.destination-branch }}" \
|
||||
--update "${{ inputs.update }}"
|
||||
--update "${{ inputs.update }}" \
|
||||
--prefix "${{ inputs.prefix }}"
|
||||
|
|
|
@ -3,9 +3,13 @@
|
|||
declare -A options
|
||||
|
||||
VERBOSE=false
|
||||
|
||||
DEBUG=false
|
||||
|
||||
: ${EXIT_ON_ERROR:=true}
|
||||
|
||||
: ${TMPDIR:=$(mktemp -d)}
|
||||
|
||||
function debug() {
|
||||
DEBUG=true
|
||||
set -x
|
||||
|
|
|
@ -4,12 +4,31 @@
|
|||
SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
source $SELF_DIR/cascading-pr-lib.sh
|
||||
|
||||
trap "rm -fr $TMPDIR" EXIT
|
||||
|
||||
function repo_login() {
|
||||
local repo="$1"
|
||||
(
|
||||
export DOT=$TMPDIR/$repo
|
||||
forgejo-curl.sh logout
|
||||
forgejo-curl.sh --token "${options[destination_token]}" login "${options[destination_url]}"
|
||||
)
|
||||
}
|
||||
|
||||
function repo_curl() {
|
||||
local repo=$1
|
||||
shift
|
||||
DOT=$TMPDIR/$repo forgejo-curl.sh "$@"
|
||||
}
|
||||
|
||||
function run() {
|
||||
options[origin_host_port]=$(host_port ${options[origin_url]})
|
||||
options[destination_host_port]=$(host_port ${options[destination_url]})
|
||||
: ${options[prefix]:=${options[origin_repo]}}
|
||||
|
||||
# login destination
|
||||
repo_login ${options[destination_repo]}
|
||||
repo_login ${options[origin_repo]}
|
||||
|
||||
# open a PR on destination
|
||||
# checkout the head of the PR
|
||||
# update the PR
|
||||
|
@ -31,34 +50,48 @@ function main() {
|
|||
--origin-url)
|
||||
shift
|
||||
options[origin_url]=$1
|
||||
shift
|
||||
;;
|
||||
--origin-repo)
|
||||
shift
|
||||
options[origin_repo]=$1
|
||||
shift
|
||||
;;
|
||||
--origin-token)
|
||||
shift
|
||||
options[origin_token]=$1
|
||||
shift
|
||||
;;
|
||||
--destination-url)
|
||||
shift
|
||||
options[destination_url]=$1
|
||||
shift
|
||||
;;
|
||||
--destination-repo)
|
||||
shift
|
||||
options[destination_repo]=$1
|
||||
shift
|
||||
;;
|
||||
--destination-token)
|
||||
shift
|
||||
options[destination_token]=$1
|
||||
shift
|
||||
;;
|
||||
--destination-branch)
|
||||
shift
|
||||
options[destination_branch]=$1
|
||||
shift
|
||||
;;
|
||||
--update)
|
||||
shift
|
||||
options[update]=$1
|
||||
shift
|
||||
;;
|
||||
--prefix)
|
||||
shift
|
||||
options[prefix]=$1
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
"${1:-run}"
|
||||
return 0
|
||||
|
|
|
@ -8,11 +8,12 @@ jobs:
|
|||
- uses: actions/checkout@v4
|
||||
- uses: SELF@vTest
|
||||
with:
|
||||
origin-url: ${{ env.$GITHUB_SERVER_URL }}
|
||||
origin-url: ${{ env.GITHUB_SERVER_URL }}
|
||||
origin-repo: user1/originrepo
|
||||
origin-token: ${{ secrets.ORIGIN_TOKEN }}
|
||||
destination-url: ${{ env.$GITHUB_SERVER_URL }}
|
||||
destination-url: ${{ env.GITHUB_SERVER_URL }}
|
||||
destination-repo: user2/destinationrepo
|
||||
destination-token: ${{ secrets.DESTINATION_TOKEN }}
|
||||
destination-branch: main
|
||||
update: upgraded
|
||||
debug: true
|
||||
|
|
15
tests/run.sh
15
tests/run.sh
|
@ -4,13 +4,11 @@
|
|||
set -e
|
||||
|
||||
SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
TMPDIR=/tmp/cascading-pr-test
|
||||
source $SELF_DIR/../cascading-pr-lib.sh
|
||||
TMPDIR=/tmp/cascading-pr
|
||||
|
||||
function push_self() {
|
||||
local host_port=$1
|
||||
|
||||
forgejo-test-helper.sh push_self_action http://user1:admin1234@$host_port user1 cascading-pr vTest
|
||||
forgejo-test-helper.sh push_self_action http://user1:admin1234@${options[host_port]} user1 cascading-pr vTest
|
||||
}
|
||||
|
||||
function user_login() {
|
||||
|
@ -25,16 +23,13 @@ function user_login() {
|
|||
function user_curl() {
|
||||
local username=$1
|
||||
shift
|
||||
(
|
||||
export DOT=$TMPDIR/$username
|
||||
forgejo-curl.sh "$@"
|
||||
)
|
||||
DOT=$TMPDIR/$username forgejo-curl.sh "$@"
|
||||
}
|
||||
|
||||
function user_token() {
|
||||
local username=$1 name=$2
|
||||
|
||||
curl -sS -f -H Content-Type:application/json --user "$username:${options[password]}" --data-raw '{"name":"'$name'","scopes":["write:repository","write:issue"]}' ${options[url]}/api/v1/users/$username/tokens | jq --raw-output .sha1
|
||||
curl -sS -f -H Content-Type:application/json --user "$username:${options[password]}" --data-raw '{"name":"'$name'","scopes":["write:repository","write:issue"]}' ${options[url]}/api/v1/users/$username/tokens | jq --raw-output .sha1 | tee $TMPDIR/$username/token
|
||||
}
|
||||
|
||||
function user_secret() {
|
||||
|
@ -83,7 +78,7 @@ function run() {
|
|||
|
||||
create_pull_request
|
||||
|
||||
push_self ${options[host_port]}
|
||||
push_self
|
||||
|
||||
echo do something
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue