mirror of
https://code.forgejo.org/actions/cascading-pr
synced 2025-03-15 06:46:59 +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-token
|
||||||
forgejo-runner.clientpid
|
forgejo-runner.clientpid
|
||||||
forgejo-runner.log
|
forgejo-runner.log
|
||||||
|
forgejo-runner-home
|
||||||
forgejo-token
|
forgejo-token
|
||||||
forgejo-api
|
forgejo-api
|
||||||
forgejo-header
|
forgejo-header
|
||||||
|
|
|
@ -12,7 +12,9 @@ forgejo-runner.sh teardown
|
||||||
forgejo.sh teardown
|
forgejo.sh teardown
|
||||||
forgejo.sh setup root admin1234 codeberg.org/forgejo/forgejo 1.21
|
forgejo.sh setup root admin1234 codeberg.org/forgejo/forgejo 1.21
|
||||||
forgejo-runner.sh setup
|
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
|
||||||
tests/run.sh --debug create_pull_request
|
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-repo "${{ inputs.destination-repo }}" \
|
||||||
--destination-token "${{ inputs.destination-token }}" \
|
--destination-token "${{ inputs.destination-token }}" \
|
||||||
--destination-branch "${{ inputs.destination-branch }}" \
|
--destination-branch "${{ inputs.destination-branch }}" \
|
||||||
--update "${{ inputs.update }}"
|
--update "${{ inputs.update }}" \
|
||||||
--prefix "${{ inputs.prefix }}"
|
--prefix "${{ inputs.prefix }}"
|
||||||
|
|
|
@ -3,9 +3,13 @@
|
||||||
declare -A options
|
declare -A options
|
||||||
|
|
||||||
VERBOSE=false
|
VERBOSE=false
|
||||||
|
|
||||||
DEBUG=false
|
DEBUG=false
|
||||||
|
|
||||||
: ${EXIT_ON_ERROR:=true}
|
: ${EXIT_ON_ERROR:=true}
|
||||||
|
|
||||||
|
: ${TMPDIR:=$(mktemp -d)}
|
||||||
|
|
||||||
function debug() {
|
function debug() {
|
||||||
DEBUG=true
|
DEBUG=true
|
||||||
set -x
|
set -x
|
||||||
|
|
|
@ -4,12 +4,31 @@
|
||||||
SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
source $SELF_DIR/cascading-pr-lib.sh
|
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() {
|
function run() {
|
||||||
options[origin_host_port]=$(host_port ${options[origin_url]})
|
options[origin_host_port]=$(host_port ${options[origin_url]})
|
||||||
options[destination_host_port]=$(host_port ${options[destination_url]})
|
options[destination_host_port]=$(host_port ${options[destination_url]})
|
||||||
: ${options[prefix]:=${options[origin_repo]}}
|
: ${options[prefix]:=${options[origin_repo]}}
|
||||||
|
|
||||||
# login destination
|
repo_login ${options[destination_repo]}
|
||||||
|
repo_login ${options[origin_repo]}
|
||||||
|
|
||||||
# open a PR on destination
|
# open a PR on destination
|
||||||
# checkout the head of the PR
|
# checkout the head of the PR
|
||||||
# update the PR
|
# update the PR
|
||||||
|
@ -31,34 +50,48 @@ function main() {
|
||||||
--origin-url)
|
--origin-url)
|
||||||
shift
|
shift
|
||||||
options[origin_url]=$1
|
options[origin_url]=$1
|
||||||
|
shift
|
||||||
;;
|
;;
|
||||||
--origin-repo)
|
--origin-repo)
|
||||||
shift
|
shift
|
||||||
options[origin_repo]=$1
|
options[origin_repo]=$1
|
||||||
|
shift
|
||||||
;;
|
;;
|
||||||
--origin-token)
|
--origin-token)
|
||||||
shift
|
shift
|
||||||
options[origin_token]=$1
|
options[origin_token]=$1
|
||||||
|
shift
|
||||||
;;
|
;;
|
||||||
--destination-url)
|
--destination-url)
|
||||||
shift
|
shift
|
||||||
options[destination_url]=$1
|
options[destination_url]=$1
|
||||||
|
shift
|
||||||
;;
|
;;
|
||||||
--destination-repo)
|
--destination-repo)
|
||||||
shift
|
shift
|
||||||
options[destination_repo]=$1
|
options[destination_repo]=$1
|
||||||
|
shift
|
||||||
;;
|
;;
|
||||||
--destination-token)
|
--destination-token)
|
||||||
shift
|
shift
|
||||||
options[destination_token]=$1
|
options[destination_token]=$1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--destination-branch)
|
||||||
|
shift
|
||||||
|
options[destination_branch]=$1
|
||||||
|
shift
|
||||||
;;
|
;;
|
||||||
--update)
|
--update)
|
||||||
shift
|
shift
|
||||||
options[update]=$1
|
options[update]=$1
|
||||||
|
shift
|
||||||
;;
|
;;
|
||||||
--prefix)
|
--prefix)
|
||||||
shift
|
shift
|
||||||
options[prefix]=$1
|
options[prefix]=$1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
"${1:-run}"
|
"${1:-run}"
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -8,11 +8,12 @@ jobs:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: SELF@vTest
|
- uses: SELF@vTest
|
||||||
with:
|
with:
|
||||||
origin-url: ${{ env.$GITHUB_SERVER_URL }}
|
origin-url: ${{ env.GITHUB_SERVER_URL }}
|
||||||
origin-repo: user1/originrepo
|
origin-repo: user1/originrepo
|
||||||
origin-token: ${{ secrets.ORIGIN_TOKEN }}
|
origin-token: ${{ secrets.ORIGIN_TOKEN }}
|
||||||
destination-url: ${{ env.$GITHUB_SERVER_URL }}
|
destination-url: ${{ env.GITHUB_SERVER_URL }}
|
||||||
destination-repo: user2/destinationrepo
|
destination-repo: user2/destinationrepo
|
||||||
destination-token: ${{ secrets.DESTINATION_TOKEN }}
|
destination-token: ${{ secrets.DESTINATION_TOKEN }}
|
||||||
|
destination-branch: main
|
||||||
update: upgraded
|
update: upgraded
|
||||||
debug: true
|
debug: true
|
||||||
|
|
15
tests/run.sh
15
tests/run.sh
|
@ -4,13 +4,11 @@
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
TMPDIR=/tmp/cascading-pr-test
|
||||||
source $SELF_DIR/../cascading-pr-lib.sh
|
source $SELF_DIR/../cascading-pr-lib.sh
|
||||||
TMPDIR=/tmp/cascading-pr
|
|
||||||
|
|
||||||
function push_self() {
|
function push_self() {
|
||||||
local host_port=$1
|
forgejo-test-helper.sh push_self_action http://user1:admin1234@${options[host_port]} user1 cascading-pr vTest
|
||||||
|
|
||||||
forgejo-test-helper.sh push_self_action http://user1:admin1234@$host_port user1 cascading-pr vTest
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function user_login() {
|
function user_login() {
|
||||||
|
@ -25,16 +23,13 @@ function user_login() {
|
||||||
function user_curl() {
|
function user_curl() {
|
||||||
local username=$1
|
local username=$1
|
||||||
shift
|
shift
|
||||||
(
|
DOT=$TMPDIR/$username forgejo-curl.sh "$@"
|
||||||
export DOT=$TMPDIR/$username
|
|
||||||
forgejo-curl.sh "$@"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function user_token() {
|
function user_token() {
|
||||||
local username=$1 name=$2
|
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() {
|
function user_secret() {
|
||||||
|
@ -83,7 +78,7 @@ function run() {
|
||||||
|
|
||||||
create_pull_request
|
create_pull_request
|
||||||
|
|
||||||
push_self ${options[host_port]}
|
push_self
|
||||||
|
|
||||||
echo do something
|
echo do something
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue