Creating Pull Request via Rest Api (with Personal Token) Does Not Trigger Actions #14283

Open
opened 2025-11-02 11:08:32 -06:00 by GiteaMirror · 8 comments
Owner

Originally created by @SupremeVoid on GitHub (Mar 21, 2025).

Description

Pull requests that get created via the rest api (with a personal access token from a user) do not trigger actions which listen to events like "pull_request" types: [ opened, closed ]

Example Action that creates a pull request via rest api.
Actions will not get executed for that automatically created pull request.

name: Create automatic pr
on:
    pull_request:
        types:
            - closed

jobs:
    create-pr:
        runs-on: act-latest
        steps:
            - name: Create automatic pull request
              env:
                  GITEA_URL: ${{ secrets.GIT_URL }}
                  BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
              run: |
                   REPO_OWNER_SLASH_NAME="${{ gitea.repository }}"
                   # here goes more action code
                   $(curl -s -X POST -H "Authorization: token $BOT_TOKEN" \
                      -H "Content-Type: application/json" \
                      -d "$PR_PAYLOAD" \
                      "$GITEA_URL/api/v1/repos/$REPO_OWNER_SLASH_NAME/pulls")

Gitea Version

1.23.3

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

Image

Git Version

2.39.5

Operating System

FreeBSD

How are you running Gitea?

We are hosting an instance of gitea via a FreeBSD binary on a machine.
I cannot provide the exact configuration. Except for networking, almost everything should be default/example like config.

Database

SQLite

Originally created by @SupremeVoid on GitHub (Mar 21, 2025). ### Description Pull requests that get created via the rest api (with a personal access token from a user) do not trigger actions which listen to events like "pull_request" types: [ opened, closed ] Example Action that creates a pull request via rest api. Actions will not get executed for that automatically created pull request. ``` name: Create automatic pr on: pull_request: types: - closed jobs: create-pr: runs-on: act-latest steps: - name: Create automatic pull request env: GITEA_URL: ${{ secrets.GIT_URL }} BOT_TOKEN: ${{ secrets.BOT_TOKEN }} run: | REPO_OWNER_SLASH_NAME="${{ gitea.repository }}" # here goes more action code $(curl -s -X POST -H "Authorization: token $BOT_TOKEN" \ -H "Content-Type: application/json" \ -d "$PR_PAYLOAD" \ "$GITEA_URL/api/v1/repos/$REPO_OWNER_SLASH_NAME/pulls") ``` ### Gitea Version 1.23.3 ### Can you reproduce the bug on the Gitea demo site? No ### Log Gist _No response_ ### Screenshots ![Image](https://github.com/user-attachments/assets/6f763b85-bd3f-44e4-b419-63b647d0cc55) ### Git Version 2.39.5 ### Operating System FreeBSD ### How are you running Gitea? We are hosting an instance of gitea via a FreeBSD binary on a machine. I cannot provide the exact configuration. Except for networking, almost everything should be default/example like config. ### Database SQLite
GiteaMirror added the topic/apitype/bug labels 2025-11-02 11:08:32 -06:00
Author
Owner

@ChristopherHX commented on GitHub (Mar 22, 2025):

as continuing here is better as far I think.

you still have a GITEA_TOKEN left in your example after applying my suggestion of using BOT_TOKEN for the env

"Authorization: token $GITEA_TOKEN" \

I can now say for sure, the api endpoint does trigger such a workflow at least in gitea 1.24..

curl -vv -X POST -H "Authorization: token PAT_TOKEN" \
                      -H "Content-Type: application/json" \
                      -d '{"title":"Amazing new feature","body":"Please pull these awesome changes in!","head":"test-patch-5","base":"main"}' \
                      "http://localhost:3000/api/v1/repos/test/private-repo/pulls"

the following content

name: MyWorkflow
on:
  pull_request:
    types:
    - opened
    - closed
env:
  CHECKOUT: actions/checkout@v4
jobs:
  meta:
    runs-on: ephemeral
    steps:
    - uses: ${{ env.CHECKOUT }}
    - uses: christopherhx/gitea-upload-artifact@v4
      with:
        name: random-file
        path: /Users/christopher/Downloads/go-raw-artifact-upload.zip
    - run: echo '${{ tojson(inputs) }}'
    - run: echo '${{ tojson(gitea) }}'
    - run: env

Verified outside of Actions

At least for PRs from forks this cannot work.

name: Create automatic pr
on:
    pull_request:
        types:
            - closed

I will downgrade soon. ( 1.23.1 works as well )

Please provide more of your setup, e.g. a stripped down workflow that should be triggered by the rest api call.

@ChristopherHX commented on GitHub (Mar 22, 2025): as continuing here is better as far I think. you still have a `GITEA_TOKEN` left in your example after applying my suggestion of using `BOT_TOKEN` for the env ``` "Authorization: token $GITEA_TOKEN" \ ``` I can now say for sure, the api endpoint does trigger such a workflow at least in gitea 1.24.. ``` curl -vv -X POST -H "Authorization: token PAT_TOKEN" \ -H "Content-Type: application/json" \ -d '{"title":"Amazing new feature","body":"Please pull these awesome changes in!","head":"test-patch-5","base":"main"}' \ "http://localhost:3000/api/v1/repos/test/private-repo/pulls" ``` the following content ```yaml name: MyWorkflow on: pull_request: types: - opened - closed env: CHECKOUT: actions/checkout@v4 jobs: meta: runs-on: ephemeral steps: - uses: ${{ env.CHECKOUT }} - uses: christopherhx/gitea-upload-artifact@v4 with: name: random-file path: /Users/christopher/Downloads/go-raw-artifact-upload.zip - run: echo '${{ tojson(inputs) }}' - run: echo '${{ tojson(gitea) }}' - run: env ``` _Verified outside of Actions_ At least for PRs from forks this cannot work. ```yaml name: Create automatic pr on: pull_request: types: - closed ``` I will downgrade soon. ( 1.23.1 works as well ) Please provide more of your setup, e.g. a stripped down workflow that should be triggered by the rest api call.
Author
Owner

@SupremeVoid commented on GitHub (Mar 22, 2025):

as continuing here is better as far I think.

you still have a GITEA_TOKEN left in your example after applying my suggestion of using BOT_TOKEN for the env

Please provide more of your setup, e.g. a stripped down workflow that should be triggered by the rest api call.

Right.

I copied the curl request part from the example I sent in discord. That included the $GITEA_TOKEN variable but in my actual code, I replaced every occurrence. (And it didnt work).

Here is the entire workflow (that creates the PR).

name: Backport Merged PR
on:
    pull_request:
        types:
            - closed

jobs:
    backport:
        if: gitea.event.pull_request.merged == true
        runs-on: act-latest
        steps:
            - name: Checkout
              uses: actions/checkout@v4
              with:
                  fetch-depth: 0 # Fetch full history instead of a shallow clone
            - name: Set up Git
              env:
                  GIT_MAIL: ${{ secrets.BOT_EMAIL }} # ${{ gitea.event.pull_request.user.email }}
                  GIT_NAME: ${{ secrets.BOT_NAME }} # ${{ gitea.event.pull_request.user.login }}
              run: |
                  git config --global user.email "$GIT_MAIL"
                  git config --global user.name "$GIT_NAME"
            - name: Create Backport
              env:
                  BOT_TOKEN: "${{ secrets.BOT_TOKEN }}"
                  GITEA_URL: "${{ secrets.GIT_URL }}"
                  PR_NUMBER: "${{ gitea.event.pull_request.number }}"
              shell: bash
              run: |
                  TITLE="${{ gitea.event.pull_request.title }}"
                  ISSUE_KEY=$(echo "$TITLE" | grep -oE '^[A-Z]+-[0-9]+')
                  if [ -z "$ISSUE_KEY" ]; then
                    echo "No Jira issue key found in pull request title."
                    exit 0
                  fi


                  # Get the JSON string of labels from the Gitea event
                  ASSIGNED_LABELS_JSON='${{ toJson(gitea.event.pull_request.labels) }}'

                  # Check if the backport pr label "backport" is assigned
                  HAS_BACKPORT_PR_LABEL=$(echo "$ASSIGNED_LABELS_JSON" | jq -r 'any(.[]; .name == "backport")')
                  if [ "$HAS_BACKPORT_PR_LABEL" == true ]; then
                    echo "Backport label found. Exiting."
                    exit 0
                  fi

                  # Retrieve all labels starting with "backport/"
                  ASSIGNED_BACKPORT_LABELS=$(echo "$ASSIGNED_LABELS_JSON" | jq -r '.[] | select(.name | startswith("backport/")) | 
                    .name')
                  if [ -z "$ASSIGNED_BACKPORT_LABELS" ]; then
                    echo "No backport labels found. Exiting."
                    exit 0
                  fi

                  # Get commits from the pull request
                  REPO_OWNER_SLASH_NAME="${{ gitea.repository }}"
                  COMMITS=$(curl -s -H "Authorization: token $BOT_TOKEN" \
                    "$GITEA_URL/api/v1/repos/$REPO_OWNER_SLASH_NAME/pulls/$PR_NUMBER/commits" | jq -r '.[] | .sha')
                  if [ -z "$COMMITS" ]; then
                    echo "No commits found for PR #$PR_NUMBER. Exiting."
                    exit 0
                  fi
                  echo "$COMMITS"

                  # Get all Repository labels
                  LABELS_JSON=$(curl -s \
                    -H "Authorization: token $BOT_TOKEN" \
                    "$GITEA_URL/api/v1/repos/$REPO_OWNER_SLASH_NAME/labels")

                  # Find the ID of the "backport" and "backport/manual" label
                  BACKPORT_LABEL_ID=$(echo "$LABELS_JSON" | jq -r '.[] | select(.name == "backport") | .id')
                  MANUAL_BACKPORT_LABEL_ID=$(echo "$LABELS_JSON" | jq -r '.[] | select(.name == "backport/manual") | .id')

                  # Create backport PRs for every backport label
                  for LABEL in $ASSIGNED_BACKPORT_LABELS; do
                    TARGET_VERSION=$(echo "$LABEL" | sed 's/backport\///')
                    TARGET_VERSION_HYPHEN=$(echo "$TARGET_VERSION" | tr '.' '-')
                    TARGET_BRANCH=HF-${TARGET_VERSION_HYPHEN}-COMPANYNAME
                    echo "Processing backport to $TARGET_BRANCH"

                    BRANCH_NAME="backport-$ISSUE_KEY-$PR_NUMBER-to-$TARGET_BRANCH"
                    git fetch origin
                    git checkout -b "$BRANCH_NAME" "origin/$TARGET_BRANCH" || {
                      echo "Failed to checkout $TARGET_BRANCH. It may not exist."
                      curl -s -X POST -H "Authorization: token $BOT_TOKEN" \
                        -H "Content-Type: application/json" \
                        -d '{"body":"Backport to $TARGET_BRANCH failed: Target branch does not exist."}'
                        "$GITEA_URL/api/v1/repos/$REPO_OWNER_SLASH_NAME/issues/$PR_NUMBER/comments"
                      continue
                    }

                    if git cherry-pick $COMMITS; then
                      echo "Cherry picking successful"
                      SUCCESS=true
                    else
                      echo "Cherry picking failed. Aborting.."
                      git cherry-pick --abort
                      SUCCESS=false

                      # Create the manual cherry-pick script
                      cat << EOF > manual_cherry_pick.sh
                        #!/bin/bash
                        set -e

                        echo "Attempting to cherry-pick commits: $COMMITS"
                        if git cherry-pick $COMMITS; then
                          echo "Cherry-pick completed successfully."
                        else
                          echo "Conflicts detected. Please resolve them manually."
                          echo "After resolving all conflicts, run: git cherry-pick --continue"
                          echo "Then re-run this script to finalize the process."
                          exit 1
                        fi

                        echo "Removing the commit that added this script..."
                        # Get the commit hash of the script's commit (the HEAD before cherry-pick)
                        script_commit=$(git rev-parse HEAD^)
                        # Reset to the state before the script was committed
                        git reset --hard "origin/$TARGET_BRANCH"
                        # Re-apply the cherry-picked commits
                        git cherry-pick $COMMITS
                        # Force push to update the remote branch
                        git push origin "$BRANCH_NAME" --force

                        echo "Script commit removed and branch updated successfully."
                        rm -f manual_cherry_pick.sh
                        echo "Script deleted from working directory."
                  EOF

                      chmod +x manual_cherry_pick.sh
                      git add manual_cherry_pick.sh
                      git commit -m "Add manual_cherry_pick.sh for conflict resolution"
                    fi

                    git push origin "$BRANCH_NAME"

                    PR_LABEL="$BACKPORT_LABEL_ID"
                    PR_TITLE="Backport $ISSUE_KEY (#${PR_NUMBER}) to $TARGET_VERSION"
                    PR_BODY=$(printf "Backport of '%s' to %s\n\nTicket: %s\nTarget Branch: %s\nTarget Version: %s\nOriginal PR: #%s" \
                      "$TITLE" "$TARGET_BRANCH" "$ISSUE_KEY" "$TARGET_BRANCH" "$TARGET_VERSION" "$PR_NUMBER")

                    if [ "$SUCCESS" = false ]; then
                      PR_TITLE="[Conflicted] Backport #${PR_NUMBER} to ${TARGET_VERSION} of ${ISSUE_KEY}"
                      PR_BODY+=$(printf "\n\n⚠️**Automatic backport failed due to conflicts.**⚠️")
                      PR_BODY+=$(printf "\n\nCheck the PR out and run ./manual_cherry_pick.sh to resolve conflicts and complete the 
                        backport.")
                      PR_LABEL="$MANUAL_BACKPORT_LABEL_ID"
                    fi

                    PR_LABEL_ARRAY=("$PR_LABEL")
                    PR_LABEL_JSON=$(printf '%s\n' "${PR_LABEL_ARRAY[@]}" | jq -R 'tonumber' | jq -s .)
                    PR_PAYLOAD=$(jq -n --arg title "$PR_TITLE" --arg body "$PR_BODY" --argjson labels "$PR_LABEL_JSON" --arg head "$BRANCH_NAME" --arg base "$TARGET_BRANCH" '{title: $title, body: $body, labels: $labels, head: $head, base: $base}')
                    PR_RESPONSE=$(curl -s -X POST -H "Authorization: token $BOT_TOKEN" \
                        -H "Content-Type: application/json" \
                        -d "$PR_PAYLOAD" \
                        "$GITEA_URL/api/v1/repos/$REPO_OWNER_SLASH_NAME/pulls")
                    echo $PR_RESPONSE
                    BACKPORT_PR_NUMBER=$(echo "$PR_RESPONSE" | jq -r '.number')

                    if [ -z "$BACKPORT_PR_NUMBER" ] || [ "$BACKPORT_PR_NUMBER" = "null" ]; then
                      echo "Failed to create PR for $TARGET_BRANCH"
                      COMMENT="Backport to $TARGET_BRANCH failed: Could not create pull request. Re-run backport action or backport manually."
                    else
                      if [ "$SUCCESS" = true ]; then
                        COMMENT="Automatic backport PR for $TARGET_BRANCH created. #$BACKPORT_PR_NUMBER"

                        # Extract pull request and repository details
                        BASE_BRANCH=$(echo "$PR_RESPONSE" | jq -r '.base.ref')
                        HEAD_BRANCH=$(echo "$PR_RESPONSE" | jq -r '.head.ref')
                        PULL_REQUEST_URL=$(echo "$PR_RESPONSE" | jq -r '.url')

                        # Define the merge title and message with computed variables
                        MERGE_TITLE="Reviewed-on: $PULL_REQUEST_URL"
                        MERGE_MESSAGE="Merge pull request '$PR_TITLE' (#$PR_NUMBER) from $HEAD_BRANCH into $BASE_BRANCH"

                        # Construct the JSON body for the API request
                        PR_MERGE_JSON_BODY=$(jq -n \
                          --arg mergestrategy "fast-forward-only" \
                          --arg title "$MERGE_TITLE" \
                          --arg message "$MERGE_MESSAGE" \
                          '{Do: $mergestrategy, MergeTitleField: $title, MergeMessageField: $message, merge_when_checks_succeed: true}')

                        # Execute the merge command via the Gitea REST API
                        curl -X POST \
                          -H "Authorization: token $BOT_TOKEN" \
                          -H "Content-Type: application/json" \
                          -d "$PR_MERGE_JSON_BODY" \
                          "$GITEA_URL/api/v1/repos/$REPO_OWNER_SLASH_NAME/pulls/$BACKPORT_PR_NUMBER/merge"
                      else
                        COMMENT=$(printf "Automatic backport to $TARGET_BRANCH failed due to conflicts.\nPlease resolve all conflicts manually in PR #%s using manual_cherry_pick.sh" \
                          "$BACKPORT_PR_NUMBER")
                      fi
                    fi

                    # Comment the original pull request with backport PR info
                    COMMENT_PAYLOAD=$(jq -n --arg body "$COMMENT"  '{body: $body}')
                    curl -s -X POST -H "Authorization: token $BOT_TOKEN" \
                        -H "Content-Type: application/json" \
                        -d "$COMMENT_PAYLOAD" \
                        "$GITEA_URL/api/v1/repos/$REPO_OWNER_SLASH_NAME/issues/$PR_NUMBER/comments"
                  done

One of the workflows that dont get triggered, on the PR that got created(opened) above:

name: CI
on:
    pull_request:
        types: [opened, synchronize]

jobs:
    build:
        name: Build
        runs-on: act-latest
        steps:
            - name: Checkout
              uses: actions/checkout@v4
            - name: Setup Node
              uses: actions/setup-node@v4
              with:
                  node-version: 20
            - name: Install
              run: npm ci
              env:
                  NPM_TOKEN: ${{ secrets.NPM_TOKEN}}
            - name: Build
              id: build-step
              run: npm run build
    test:
        name: Unit-Tests
        runs-on: act-latest
        steps:
            - name: Checkout
              uses: actions/checkout@v4
            - name: Setup Node
              uses: actions/setup-node@v4
              with:
                  node-version: 20
            - name: Install
              run: npm ci
              env:
                  NPM_TOKEN: ${{ secrets.NPM_TOKEN}}
            - name: Run Jest
              id: test-step
              run: npm run test
    prettier:
        name: Prettier
        runs-on: act-latest
        steps:
            - name: Checkout
              uses: actions/checkout@v4
            - name: Setup Node
              uses: actions/setup-node@v4
              with:
                  node-version: 20
            - name: Install
              run: npm ci
              env:
                  NPM_TOKEN: ${{ secrets.NPM_TOKEN}}
            - name: Run Prettier
              run: |
                  npx prettier --check .

@SupremeVoid commented on GitHub (Mar 22, 2025): > as continuing here is better as far I think. > > you still have a `GITEA_TOKEN` left in your example after applying my suggestion of using `BOT_TOKEN` for the env > > Please provide more of your setup, e.g. a stripped down workflow that should be triggered by the rest api call. Right. I copied the curl request part from the example I sent in discord. That included the $GITEA_TOKEN variable but in my actual code, I replaced every occurrence. (And it didnt work). Here is the entire workflow (that creates the PR). ``` name: Backport Merged PR on: pull_request: types: - closed jobs: backport: if: gitea.event.pull_request.merged == true runs-on: act-latest steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 # Fetch full history instead of a shallow clone - name: Set up Git env: GIT_MAIL: ${{ secrets.BOT_EMAIL }} # ${{ gitea.event.pull_request.user.email }} GIT_NAME: ${{ secrets.BOT_NAME }} # ${{ gitea.event.pull_request.user.login }} run: | git config --global user.email "$GIT_MAIL" git config --global user.name "$GIT_NAME" - name: Create Backport env: BOT_TOKEN: "${{ secrets.BOT_TOKEN }}" GITEA_URL: "${{ secrets.GIT_URL }}" PR_NUMBER: "${{ gitea.event.pull_request.number }}" shell: bash run: | TITLE="${{ gitea.event.pull_request.title }}" ISSUE_KEY=$(echo "$TITLE" | grep -oE '^[A-Z]+-[0-9]+') if [ -z "$ISSUE_KEY" ]; then echo "No Jira issue key found in pull request title." exit 0 fi # Get the JSON string of labels from the Gitea event ASSIGNED_LABELS_JSON='${{ toJson(gitea.event.pull_request.labels) }}' # Check if the backport pr label "backport" is assigned HAS_BACKPORT_PR_LABEL=$(echo "$ASSIGNED_LABELS_JSON" | jq -r 'any(.[]; .name == "backport")') if [ "$HAS_BACKPORT_PR_LABEL" == true ]; then echo "Backport label found. Exiting." exit 0 fi # Retrieve all labels starting with "backport/" ASSIGNED_BACKPORT_LABELS=$(echo "$ASSIGNED_LABELS_JSON" | jq -r '.[] | select(.name | startswith("backport/")) | .name') if [ -z "$ASSIGNED_BACKPORT_LABELS" ]; then echo "No backport labels found. Exiting." exit 0 fi # Get commits from the pull request REPO_OWNER_SLASH_NAME="${{ gitea.repository }}" COMMITS=$(curl -s -H "Authorization: token $BOT_TOKEN" \ "$GITEA_URL/api/v1/repos/$REPO_OWNER_SLASH_NAME/pulls/$PR_NUMBER/commits" | jq -r '.[] | .sha') if [ -z "$COMMITS" ]; then echo "No commits found for PR #$PR_NUMBER. Exiting." exit 0 fi echo "$COMMITS" # Get all Repository labels LABELS_JSON=$(curl -s \ -H "Authorization: token $BOT_TOKEN" \ "$GITEA_URL/api/v1/repos/$REPO_OWNER_SLASH_NAME/labels") # Find the ID of the "backport" and "backport/manual" label BACKPORT_LABEL_ID=$(echo "$LABELS_JSON" | jq -r '.[] | select(.name == "backport") | .id') MANUAL_BACKPORT_LABEL_ID=$(echo "$LABELS_JSON" | jq -r '.[] | select(.name == "backport/manual") | .id') # Create backport PRs for every backport label for LABEL in $ASSIGNED_BACKPORT_LABELS; do TARGET_VERSION=$(echo "$LABEL" | sed 's/backport\///') TARGET_VERSION_HYPHEN=$(echo "$TARGET_VERSION" | tr '.' '-') TARGET_BRANCH=HF-${TARGET_VERSION_HYPHEN}-COMPANYNAME echo "Processing backport to $TARGET_BRANCH" BRANCH_NAME="backport-$ISSUE_KEY-$PR_NUMBER-to-$TARGET_BRANCH" git fetch origin git checkout -b "$BRANCH_NAME" "origin/$TARGET_BRANCH" || { echo "Failed to checkout $TARGET_BRANCH. It may not exist." curl -s -X POST -H "Authorization: token $BOT_TOKEN" \ -H "Content-Type: application/json" \ -d '{"body":"Backport to $TARGET_BRANCH failed: Target branch does not exist."}' "$GITEA_URL/api/v1/repos/$REPO_OWNER_SLASH_NAME/issues/$PR_NUMBER/comments" continue } if git cherry-pick $COMMITS; then echo "Cherry picking successful" SUCCESS=true else echo "Cherry picking failed. Aborting.." git cherry-pick --abort SUCCESS=false # Create the manual cherry-pick script cat << EOF > manual_cherry_pick.sh #!/bin/bash set -e echo "Attempting to cherry-pick commits: $COMMITS" if git cherry-pick $COMMITS; then echo "Cherry-pick completed successfully." else echo "Conflicts detected. Please resolve them manually." echo "After resolving all conflicts, run: git cherry-pick --continue" echo "Then re-run this script to finalize the process." exit 1 fi echo "Removing the commit that added this script..." # Get the commit hash of the script's commit (the HEAD before cherry-pick) script_commit=$(git rev-parse HEAD^) # Reset to the state before the script was committed git reset --hard "origin/$TARGET_BRANCH" # Re-apply the cherry-picked commits git cherry-pick $COMMITS # Force push to update the remote branch git push origin "$BRANCH_NAME" --force echo "Script commit removed and branch updated successfully." rm -f manual_cherry_pick.sh echo "Script deleted from working directory." EOF chmod +x manual_cherry_pick.sh git add manual_cherry_pick.sh git commit -m "Add manual_cherry_pick.sh for conflict resolution" fi git push origin "$BRANCH_NAME" PR_LABEL="$BACKPORT_LABEL_ID" PR_TITLE="Backport $ISSUE_KEY (#${PR_NUMBER}) to $TARGET_VERSION" PR_BODY=$(printf "Backport of '%s' to %s\n\nTicket: %s\nTarget Branch: %s\nTarget Version: %s\nOriginal PR: #%s" \ "$TITLE" "$TARGET_BRANCH" "$ISSUE_KEY" "$TARGET_BRANCH" "$TARGET_VERSION" "$PR_NUMBER") if [ "$SUCCESS" = false ]; then PR_TITLE="[Conflicted] Backport #${PR_NUMBER} to ${TARGET_VERSION} of ${ISSUE_KEY}" PR_BODY+=$(printf "\n\n⚠️**Automatic backport failed due to conflicts.**⚠️") PR_BODY+=$(printf "\n\nCheck the PR out and run ./manual_cherry_pick.sh to resolve conflicts and complete the backport.") PR_LABEL="$MANUAL_BACKPORT_LABEL_ID" fi PR_LABEL_ARRAY=("$PR_LABEL") PR_LABEL_JSON=$(printf '%s\n' "${PR_LABEL_ARRAY[@]}" | jq -R 'tonumber' | jq -s .) PR_PAYLOAD=$(jq -n --arg title "$PR_TITLE" --arg body "$PR_BODY" --argjson labels "$PR_LABEL_JSON" --arg head "$BRANCH_NAME" --arg base "$TARGET_BRANCH" '{title: $title, body: $body, labels: $labels, head: $head, base: $base}') PR_RESPONSE=$(curl -s -X POST -H "Authorization: token $BOT_TOKEN" \ -H "Content-Type: application/json" \ -d "$PR_PAYLOAD" \ "$GITEA_URL/api/v1/repos/$REPO_OWNER_SLASH_NAME/pulls") echo $PR_RESPONSE BACKPORT_PR_NUMBER=$(echo "$PR_RESPONSE" | jq -r '.number') if [ -z "$BACKPORT_PR_NUMBER" ] || [ "$BACKPORT_PR_NUMBER" = "null" ]; then echo "Failed to create PR for $TARGET_BRANCH" COMMENT="Backport to $TARGET_BRANCH failed: Could not create pull request. Re-run backport action or backport manually." else if [ "$SUCCESS" = true ]; then COMMENT="Automatic backport PR for $TARGET_BRANCH created. #$BACKPORT_PR_NUMBER" # Extract pull request and repository details BASE_BRANCH=$(echo "$PR_RESPONSE" | jq -r '.base.ref') HEAD_BRANCH=$(echo "$PR_RESPONSE" | jq -r '.head.ref') PULL_REQUEST_URL=$(echo "$PR_RESPONSE" | jq -r '.url') # Define the merge title and message with computed variables MERGE_TITLE="Reviewed-on: $PULL_REQUEST_URL" MERGE_MESSAGE="Merge pull request '$PR_TITLE' (#$PR_NUMBER) from $HEAD_BRANCH into $BASE_BRANCH" # Construct the JSON body for the API request PR_MERGE_JSON_BODY=$(jq -n \ --arg mergestrategy "fast-forward-only" \ --arg title "$MERGE_TITLE" \ --arg message "$MERGE_MESSAGE" \ '{Do: $mergestrategy, MergeTitleField: $title, MergeMessageField: $message, merge_when_checks_succeed: true}') # Execute the merge command via the Gitea REST API curl -X POST \ -H "Authorization: token $BOT_TOKEN" \ -H "Content-Type: application/json" \ -d "$PR_MERGE_JSON_BODY" \ "$GITEA_URL/api/v1/repos/$REPO_OWNER_SLASH_NAME/pulls/$BACKPORT_PR_NUMBER/merge" else COMMENT=$(printf "Automatic backport to $TARGET_BRANCH failed due to conflicts.\nPlease resolve all conflicts manually in PR #%s using manual_cherry_pick.sh" \ "$BACKPORT_PR_NUMBER") fi fi # Comment the original pull request with backport PR info COMMENT_PAYLOAD=$(jq -n --arg body "$COMMENT" '{body: $body}') curl -s -X POST -H "Authorization: token $BOT_TOKEN" \ -H "Content-Type: application/json" \ -d "$COMMENT_PAYLOAD" \ "$GITEA_URL/api/v1/repos/$REPO_OWNER_SLASH_NAME/issues/$PR_NUMBER/comments" done ``` One of the workflows that dont get triggered, on the PR that got created(opened) above: ``` name: CI on: pull_request: types: [opened, synchronize] jobs: build: name: Build runs-on: act-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Setup Node uses: actions/setup-node@v4 with: node-version: 20 - name: Install run: npm ci env: NPM_TOKEN: ${{ secrets.NPM_TOKEN}} - name: Build id: build-step run: npm run build test: name: Unit-Tests runs-on: act-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Setup Node uses: actions/setup-node@v4 with: node-version: 20 - name: Install run: npm ci env: NPM_TOKEN: ${{ secrets.NPM_TOKEN}} - name: Run Jest id: test-step run: npm run test prettier: name: Prettier runs-on: act-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Setup Node uses: actions/setup-node@v4 with: node-version: 20 - name: Install run: npm ci env: NPM_TOKEN: ${{ secrets.NPM_TOKEN}} - name: Run Prettier run: | npx prettier --check . ```
Author
Owner

@ChristopherHX commented on GitHub (Mar 23, 2025):

Your workflow files are fine and yes they work on my end (after understanding how they work) on 1.23.1 (slow linux hardware), I know I'm behind on that instance.

  • Create Secrets.... and add PAT
  • create label backport, backport/1.0.2
  • create branch HF-1-0-2-COMPANYNAME
  • change readme and open pr with label backport/1.0.2
  • fast forward merge
  • backport starts
  • pr is opened like on your end with actions running
Image

The checks just don't succeed for me, unless I stub them due to unrelated reasons.

Does your Gitea log file show any messages?

@ChristopherHX commented on GitHub (Mar 23, 2025): Your workflow files are fine and yes they work on my end (after understanding how they work) on 1.23.1 (slow linux hardware), I know I'm behind on that instance. - Create Secrets.... and add PAT - create label backport, backport/1.0.2 - create branch HF-1-0-2-COMPANYNAME - change readme and open pr with label backport/1.0.2 - fast forward merge - backport starts - pr is opened like on your end with actions running <img width="974" alt="Image" src="https://github.com/user-attachments/assets/3266c2c4-2a04-4bee-86b2-52bcd4f5c77b" /> The checks just don't succeed for me, unless I stub them due to unrelated reasons. Does your Gitea log file show any messages?
Author
Owner

@SupremeVoid commented on GitHub (Mar 24, 2025):

Does your Gitea log file show any messages?

I need to check with our Sys Admin as I do not have access to the logs directly.

In the meantime, i tested it with a local 1.23.3 installation of gitea on my machine and it works. (I setup everything the same, except for a postgress DB instead of Sqllite)
So I assume something must be wrong with our Gitea instance? (except for it running awefully slow)

@SupremeVoid commented on GitHub (Mar 24, 2025): > Does your Gitea log file show any messages? I need to check with our Sys Admin as I do not have access to the logs directly. In the meantime, i tested it with a local 1.23.3 installation of gitea on my machine and it works. (I setup everything the same, except for a postgress DB instead of Sqllite) So I assume something must be wrong with our Gitea instance? (except for it running awefully slow)
Author
Owner

@SupremeVoid commented on GitHub (Mar 24, 2025):

I checked the logs. There is nothing interesting (or nothing at all) at the corresponding times, where the action should have run.

Edit: I also checked our gitea app.ini configuration now. Could it be related to webhook or some other configuration?

@SupremeVoid commented on GitHub (Mar 24, 2025): I checked the logs. There is nothing interesting (or nothing at all) at the corresponding times, where the action should have run. *Edit*: I also checked our gitea app.ini configuration now. Could it be related to webhook or some other configuration?
Author
Owner

@SupremeVoid commented on GitHub (Mar 25, 2025):

@ChristopherHX any more suggestions or things I should check or try out?

@SupremeVoid commented on GitHub (Mar 25, 2025): @ChristopherHX any more suggestions or things I should check or try out?
Author
Owner

@lunny commented on GitHub (Mar 25, 2025):

Giteabot will not trigger actions because of event recycles. This is by design. You could use a PAT to do that.

@lunny commented on GitHub (Mar 25, 2025): Giteabot will not trigger actions because of event recycles. This is by design. You could use a PAT to do that.
Author
Owner

@SupremeVoid commented on GitHub (Mar 25, 2025):

Giteabot will not trigger actions because of event recycles. This is by design. You could use a PAT to do that.

I am using a PAT, that is what we are trying to resolve. We (Christopher and me) confirmed that it should work but our gitea instance seems to have an issue triggering actions created via rest api (With PAT)

@SupremeVoid commented on GitHub (Mar 25, 2025): > Giteabot will not trigger actions because of event recycles. This is by design. You could use a PAT to do that. I am using a PAT, that is what we are trying to resolve. We (Christopher and me) confirmed that it should work but our gitea instance seems to have an issue triggering actions created via rest api (With PAT)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#14283