gpt4 book ai didi

Github 操作 : Stop the action if PR already exists

转载 作者:行者123 更新时间:2023-12-03 08:02:08 25 4
gpt4 key购买 nike

我正在通过 GitHub 操作创建自动 PR,因此每当 dev 分支上发生新推送时。自动创建从 devmaster

的 PR

我想更改:如果已经存在 PR ( master <- dev ),则无需运行此操作,那么如何才能我检查 PR 是否已经存在?

Github 操作

name: Pull Request Action
on:
push:
branches: ['dev']

jobs:
create-pull-request:
runs-on: ubuntu-latest
steps:
- name: Create Pull Request
uses: actions/github-script@v6
with:
script: |
const { repo, owner } = context.repo;
const result = await github.rest.pulls.create({
title: 'Master Sync : Auto Generated PR',
owner,
repo,
head: '${{ github.ref_name }}',
base: 'master',
body: [
'This PR is auto-generated by',
'[actions/github-script](https://github.com/actions/github-script).'
].join('\n')
});
github.rest.issues.addLabels({
owner,
repo,
issue_number: result.data.number,
labels: ['feature', 'automated pr']
});

最佳答案

没有任何条件可以直接在作业本身的 if 步骤中使用,但您可以使用 GitHub CLI 查看是否已经存在这样的 PR,然后提前退出:

steps:
- name: Check if PR exists
id: check
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
prs=$(gh pr list \
--repo "$GITHUB_REPOSITORY" \
--head 'dev' \
--base 'master' \
--json title \
--jq 'length')
if ((prs > 0)); then
echo "skip=true" >> "$GITHUB_OUTPUT"
fi

- name: Create pull request
if: '!steps.check.outputs.skip'
# ...

关于Github 操作 : Stop the action if PR already exists,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73812503/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com