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 Check Require Label GitHub Actions Workflow #13

Merged
merged 1 commit into from
May 4, 2024

Conversation

ucan-lab
Copy link
Owner

@ucan-lab ucan-lab commented May 4, 2024

User description

close #12


Type

enhancement, configuration changes


Description

  • プルリクエストのトリガーイベントに labeled, unlabeled, reopened を追加して、より多様なイベントでワークフローが動作するように変更
  • ラベル付与の条件を opened または synchronize のアクションに限定し、その他のアクションではラベル付与をスキップ
  • 新しいジョブ check-require-label を追加し、プルリクエストに bug, chore, dependencies, documentation, enhancement, refactor, release のいずれかのラベルがない場合にエラーを出すように設定

Changes walkthrough

Relevant files
Configuration changes
assign-label.yaml
GitHub Actionsのワークフロー更新: ラベル管理と必須チェック追加                                   

.github/workflows/assign-label.yaml

  • プルリクエストのトリガータイプに labeled, unlabeled, reopened を追加
  • ラベル自動付与の条件を opened または synchronize の場合に限定
  • 必須ラベルチェックの新しいジョブを追加し、特定のラベルが付与されていない場合に失敗するように設定
  • +31/-1   

    PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @github-actions github-actions bot added the chore 種別: ツールやライブラリの変更 label May 4, 2024
    @ucan-lab ucan-lab removed the chore 種別: ツールやライブラリの変更 label May 4, 2024
    Copy link

    github-actions bot commented May 4, 2024

    PR Description updated to latest commit (67be4af)

    Copy link

    github-actions bot commented May 4, 2024

    PR Review

    ⏱️ Estimated effort to review [1-5]

    2, このPRはGitHub Actionsのワークフロー設定ファイルの更新を含んでおり、変更点が明確であり、レビューにかかる時間と労力は比較的少ないです。

    🧪 Relevant tests

    No

    🔍 Possible issues

    Possible Bug: ラベルがない場合のエラーメッセージが不明瞭です。エラーメッセージにはどのラベルが必要か具体的に示すべきです。

    🔒 Security concerns

    No

    Code feedback:
    relevant file.github/workflows/assign-label.yaml
    suggestion      

    types 配列に closed イベントを追加することで、プルリクエストが閉じられた際にも適切なラベルが付与されているか確認できます。これにより、プロジェクトの整理と追跡が容易になります。 [important]

    relevant linetypes: [opened, labeled, unlabeled, synchronize, reopened]

    relevant file.github/workflows/assign-label.yaml
    suggestion      

    check-require-label ジョブの if 条件をシンプルにするために、fromJSON 関数を使用して steps.labels.outputs.json から直接ラベルをチェックする方法を検討してください。これにより、コードの可読性が向上します。 [medium]

    relevant lineif: >-


    ✨ Review tool usage guide:

    Overview:
    The review tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be added by configuring the tool.

    The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.

    • When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:
    /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
    
    [pr_reviewer]
    some_config1=...
    some_config2=...
    

    See the review usage page for a comprehensive guide on using this tool.

    @ucan-lab ucan-lab added the chore 種別: ツールやライブラリの変更 label May 4, 2024
    Copy link

    github-actions bot commented May 4, 2024

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Best practice
    JSON 文字列をシングルクォートで囲むことを推奨します。

    fromJson 関数を使用する際には、JSON 文字列を正しく解析するために、シングルクォートを使用して文字列を囲むことを推奨します。これにより、YAML
    パーサーが予期せぬ方法で文字列を解釈するのを防ぎます。

    .github/workflows/assign-label.yaml [16]

    -if: ${{ contains(fromJson('["opened", "synchronize"]'), github.event.action) }}
    +if: ${{ contains(fromJson('"["opened", "synchronize"]"'), github.event.action) }}
     
    環境変数の参照を明示的にします。

    GitHub Actions の run コマンドで環境変数を使用する際は、明示的に ${{ }} を使用して変数を参照することを推奨します。これにより、YAML
    パーサーが変数を正しく解釈しやすくなります。

    .github/workflows/assign-label.yaml [35]

    -run: echo "${{steps.labels.outputs.json}}"
    +run: echo "${{ steps.labels.outputs.json }}"
     
    Bug
    fromJson 関数の引数を正しい形式に修正します。

    GitHub Actions の条件式で fromJson 関数を使用する際は、正しい JSON 形式を確認してください。現在のコードでは、fromJSON
    の引数が不正な形式になっています。

    .github/workflows/assign-label.yaml [38-44]

     if: >-
    -  ! contains(fromJSON(steps.labels.outputs.json), 'bug') &&
    -  ! contains(fromJSON(steps.labels.outputs.json), 'chore') &&
    -  ! contains(fromJSON(steps.labels.outputs.json), 'dependencies') &&
    -  ! contains(fromJSON(steps.labels.outputs.json), 'documentation') &&
    -  ! contains(fromJSON(steps.labels.outputs.json), 'enhancement') &&
    -  ! contains(fromJSON(steps.labels.outputs.json), 'refactor') &&
    -  ! contains(fromJSON(steps.labels.outputs.json), 'release')
    +  ! contains(fromJSON('${{ steps.labels.outputs.json }}'), 'bug') &&
    +  ! contains(fromJSON('${{ steps.labels.outputs.json }}'), 'chore') &&
    +  ! contains(fromJSON('${{ steps.labels.outputs.json }}'), 'dependencies') &&
    +  ! contains(fromJSON('${{ steps.labels.outputs.json }}'), 'documentation') &&
    +  ! contains(fromJSON('${{ steps.labels.outputs.json }}'), 'enhancement') &&
    +  ! contains(fromJSON('${{ steps.labels.outputs.json }}'), 'refactor') &&
    +  ! contains(fromJSON('${{ steps.labels.outputs.json }}'), 'release')
     
    Enhancement
    gh pr view コマンドのエラーハンドリングを追加します。

    gh pr view コマンドの出力を jq
    で処理する際、エラーハンドリングを追加することを推奨します。これにより、コマンドが失敗した場合にスクリプトが適切に対応できるようになります。

    .github/workflows/assign-label.yaml [32]

    -json=$(gh pr view "$PR_NUMBER" --json labels | jq -c '.labels|map(.name)')
    +json=$(gh pr view "$PR_NUMBER" --json labels | jq -c '.labels|map(.name)') || { echo "Failed to fetch labels"; exit 1; }
     

    ✨ Improve tool usage guide:

    Overview:
    The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.

    • When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:
    /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
    
    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    

    See the improve usage page for a comprehensive guide on using this tool.

    @ucan-lab ucan-lab force-pushed the chore-12-check-require-label branch from a109f2b to f4c505f Compare May 4, 2024 19:20
    @ucan-lab ucan-lab merged commit 188471c into main May 4, 2024
    2 checks passed
    @ucan-lab ucan-lab deleted the chore-12-check-require-label branch May 4, 2024 19:25
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    chore 種別: ツールやライブラリの変更
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    Add Check Require Label GitHub Actions Workflow
    1 participant