[newSolution]Who can add 1 more problem of LeetCode 2054 #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Daily / Handle issue close | |
| # 当有issue被关闭时,自动在project中填写完成日期 | |
| on: | |
| issues: | |
| types: [closed] | |
| permissions: | |
| issues: read | |
| repository-projects: write | |
| env: | |
| PROJECT_ID: ${{ secrets.ONE_PROBLEM_ONE_DAY_PROJECT_ID }} | |
| FINISH_DATE_FIELD_ID: ${{ secrets.ONE_PROBLEM_ONE_DAY_FINISH_DATE_FIELD_ID }} | |
| jobs: | |
| close: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Set finish date & done | |
| id: set-state | |
| env: | |
| GH_TOKEN: ${{ secrets.ONE_PROBLEM_ONE_DAY_PAT }} | |
| run: | | |
| issue_node_id="${{ github.event.issue.node_id }}" | |
| closed_at="${{ github.event.issue.closed_at }}" | |
| date_cn=$(date -d "$closed_at +8 hours" +%F) | |
| echo "Query project item_id via Issue.projectItems..." | |
| item_id=$(gh api graphql -f query=' | |
| query($issue:ID!) { | |
| node(id:$issue) { | |
| ... on Issue { | |
| projectItems(first:20) { | |
| nodes { | |
| id | |
| project { id } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| ' -f issue="$issue_node_id" \ | |
| --jq ".data.node.projectItems.nodes[] | |
| | select(.project.id==\"$PROJECT_ID\") | |
| | .id") | |
| if [[ -z "$item_id" ]]; then | |
| echo "Issue not in project, skip" | |
| echo "skip=true" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| echo "Found item_id = $item_id" | |
| echo "Set Finish Date field -> $date_cn" | |
| gh api graphql -f query=' | |
| mutation($project:ID!, $item:ID!, $field:ID!, $date:Date!) { | |
| updateProjectV2ItemFieldValue(input:{ | |
| projectId:$project | |
| itemId:$item | |
| fieldId:$field | |
| value:{ date:$date } | |
| }) { | |
| projectV2Item { id } | |
| } | |
| } | |
| ' \ | |
| -f project="$PROJECT_ID" \ | |
| -f item="$item_id" \ | |
| -f field="$FINISH_DATE_FIELD_ID" \ | |
| -f date="$date_cn" | |
| echo "date_cn=$date_cn" >> $GITHUB_OUTPUT | |
| echo "Set Finish Date successfully ✅" | |
| - name: Resolve workflow path | |
| id: resolve-workflow-path | |
| if: steps.set-state.outputs.skip != 'true' | |
| env: | |
| REPO: ${{ github.repository }} | |
| run: | | |
| workflow_path=${GITHUB_WORKFLOW_REF#*/} # 去掉owner | |
| workflow_path=${workflow_path#*/} # 去掉repo名 | |
| workflow_path=${workflow_path%@*} # 去掉@ref | |
| action_file="https://github.com/$REPO/blob/$GITHUB_SHA/$workflow_path" | |
| echo "action_file=$action_file" >> $GITHUB_OUTPUT | |
| - name: Generate GitHub App token | |
| id: app-token | |
| uses: actions/create-github-app-token@v1 | |
| with: | |
| app-id: ${{ vars.DAILY_BOT_APP_ID }} | |
| private-key: ${{ secrets.DAILY_BOT_APP_PRIVATE_KEY }} | |
| - name: Comment on issue | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ steps.app-token.outputs.token }} | |
| script: | | |
| const now = new Date().toLocaleString('zh-CN', { | |
| timeZone: 'Asia/Shanghai', | |
| hour12: false | |
| }); | |
| const actionFile = `${{ steps.resolve-workflow-path.outputs.action_file }}`; | |
| const setToDate = `${{ steps.set-state.outputs.date_cn }}`; | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| body: `Set finish date = ${setToDate} in project.\n🕒 Time (Beijing, UTC+8): ${now}\n🤖 Triggered by [1problem1day Bot](https://github.com/apps/1problem1day) according to [action file](${actionFile})` | |
| }); |