From 5b1440e14abc3f5da3c1a311ec616996fed9b11c Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Mon, 13 Sep 2021 22:46:57 +0200 Subject: [PATCH] devops: rework client side changes bot (#8877) --- .../pr_check_client_side_changes.yml | 47 ++++++++++++++----- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/.github/workflows/pr_check_client_side_changes.yml b/.github/workflows/pr_check_client_side_changes.yml index 219e8b4405..6c10afaa22 100644 --- a/.github/workflows/pr_check_client_side_changes.yml +++ b/.github/workflows/pr_check_client_side_changes.yml @@ -14,20 +14,41 @@ jobs: - name: Create GitHub issue uses: actions/github-script@v4 with: + github-token: ${{ secrets.GH_SERVICE_ACCOUNT_TOKEN }} script: | const { data } = await github.git.getCommit({ - owner: 'microsoft', - repo: 'playwright', - commit_sha: '${{ github.sha }}', + owner: context.repo.owner, + repo: context.repo.repo, + commit_sha: context.sha, }); const commitHeader = data.message.split('\n')[0]; - const body = `${{ github.sha }} made changes to the client, this needs to get applied in: - - [ ] Python - - [ ] Java - - [ ] .NET`; - await github.issues.create({ - owner: 'microsoft', - repo: 'playwright', - title: `[Ports] Apply: ${commitHeader}`, - body, - }); + + const title = '[Ports]: Backport client side changes'; + for (const repo of ['playwright-python', 'playwright-java', 'playwright-dotnet']) { + const { data: issuesData } = await github.search.issuesAndPullRequests({ + q: `is:issue is:open repo:microsoft/${repo} in:title "${title}"` + }) + let issueNumber = null; + let issueBody = ''; + if (issuesData.total_count > 0) { + issueNumber = issuesData.items[0].number + issueBody = issuesData.items[0].body + } else { + const { data: issueCreateData } = await github.issues.create({ + owner: context.repo.owner, + repo: repo, + title, + body: 'Please backport client side changes: \n', + }); + issueNumber = issueCreateData.number; + issueBody = issueCreateData.body; + } + const newBody = issueBody.trimEnd() + ` + - [ ] https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${context.sha} (${commitHeader})`; + const data = await github.issues.update({ + owner: context.repo.owner, + repo: repo, + issue_number: issueNumber, + body: newBody + }) + }