Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add common scripts to get original PR's information in other bot-sdk repositories #74

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Yang-33
Copy link
Contributor

@Yang-33 Yang-33 commented Nov 25, 2024

Currently, the bot-sdk repositories automatically create PRs based on updates to line-openapi.

The titles and descriptions of these automatically generated PRs are sometimes filled in by maintainers, but not always. I realized that when creating a PR in the SDK repositories, we can obtain information such as the title and description by retrieving the PR information from line-openapi.

I have implemented and tested a proof of concept for this. Since it seems practical, this change adds scripts to line-openapi. While we could write the same script in each SDK repository, placing it in line-openapi makes maintenance easier. Since line-openapi is registered as a submodule in the bot-sdk repositories, we can call the same script.

In each SDK repository, we need to write a GitHub workflow like the following:

name: Generate OpenAPI based code

on:
  workflow_dispatch:
  push:
    branches:
      - master

jobs:
  tests:
    name: Generate OpenAPI based code
    runs-on: ubuntu-latest

    steps:
      # Setup
      - uses: actions/checkout@v4
        with:
          submodules: recursive
      - name: Update submodules
        run: git submodule update --remote --recursive
+     - uses: actions/setup-node@v4
      - uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: 17
          architecture: x64

      - name: Install Dependency
        run: npm ci

      # Generate codes
      - run: |
          python3 generate-code.py
      - run: |
          diff=$(git --no-pager diff --name-only)
          echo "DIFF_IS_EMPTY='false'" >> $GITHUB_ENV
          echo "CURRENT_DATETIME=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV
      - if: ${{ env.DIFF_IS_EMPTY != 'true' }}
        run: |
+         # Determine Change Type via Submodule Script
+         CHANGE_TYPE=$(npx zx ./line-openapi/tools/determine-change-type.mjs)
+         echo "Determined change type: $CHANGE_TYPE"

+         # Determine PR title and body
+         if [ "$CHANGE_TYPE" == "submodule-update" ]; then
+           # Fetch PR info from submodule
+           npx zx ./line-openapi/tools/get-pr-info.mjs
+           PR_INFO=$(cat pr_info.json)
+           TITLE=$(echo "$PR_INFO" | jq -r '.title')
+           BODY=$(echo "$PR_INFO" | jq -r '.url')$'\n\n'$(echo "$PR_INFO" | jq -r '.body')
+         else
+           # Default PR title and body
+           TITLE="Codes are generated by openapi generator"
+           BODY="⚠Reviewer: Please edit this description to include relevant information about the changes.⚠"
          fi

          BRANCH_NAME="update-diff-${{ env.CURRENT_DATETIME }}"

          git config user.name github-actions
          git config user.email [email protected]
          git checkout -b $BRANCH_NAME

          git add line-openapi
          git add lib/**
          git commit -m "Codes are generated by openapi"

+         git push origin $BRANCH_NAME
+         gh pr create -B ${{ github.ref_name }} -H $BRANCH_NAME -t "$TITLE" -b "$BODY" --label "line-openapi-update"
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

As a result, we may automate PR title and description like this in each bot-sdk repository:
image

Comment on lines +23 to +29
if (lastCommit.includes(submoduleDir)) {
console.log("submodule-update");
} else if (hasUpdate) {
console.log("submodule-update");
} else {
console.log("other");
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code is generated in each repository in the following two cases:

  1. When a maintainer manually executes GitHub Actions.
  2. When Renovate pushes a commit that updates line-openapi, triggering GitHub Actions to run.

In other cases, the line-openapi PR description should not be reflected.

@Yang-33 Yang-33 self-assigned this Nov 25, 2024
@Yang-33 Yang-33 enabled auto-merge (squash) November 25, 2024 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant