diff --git a/.github/workflows/link-pull-request-issues.yml b/.github/workflows/link-pull-request-issues.yml new file mode 100644 index 000000000000..f28f905e7a24 --- /dev/null +++ b/.github/workflows/link-pull-request-issues.yml @@ -0,0 +1,90 @@ +name: Link pull requests to issues + +on: + pull_request_target: + types: + - opened + - edited + - reopened + +permissions: + contents: read + +jobs: + link-issue: + if: github.repository == 'php/php-src' + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + - uses: actions/github-script@v7 + with: + script: | + const title = context.payload.pull_request.title; + const matches = [...title.matchAll(/\bFix GH-(\d+)\b/g)]; + const pullRequest = context.payload.pull_request; + const body = pullRequest.body ?? ''; + const marker = ''; + const withoutManagedReference = body + .replace(/\n?\nFixes #\d+\n?/g, '') + .trimEnd(); + + if (matches.length !== 1) { + if (matches.length > 1) { + core.warning(`Expected one GH issue in the title, found ${matches.length}.`); + } + if (body.includes(marker)) { + await github.rest.issues.update({ + ...context.repo, + issue_number: pullRequest.number, + body: withoutManagedReference, + }); + } + return; + } + + const issueNumber = Number(matches[0][1]); + const { owner, repo } = context.repo; + const { data: issue } = await github.rest.issues.get({ + owner, + repo, + issue_number: issueNumber, + }); + + if (issue.pull_request) { + core.warning(`#${issueNumber} is a pull request, not an issue.`); + if (body.includes(marker)) { + await github.rest.issues.update({ + ...context.repo, + issue_number: pullRequest.number, + body: withoutManagedReference, + }); + } + return; + } + + const closingReference = new RegExp( + `\\b(?:close|closes|fix|fixes|resolve|resolves)\\s+(?:#|GH-)${issueNumber}\\b`, + 'i', + ); + + if (closingReference.test(withoutManagedReference)) { + if (body.includes(marker)) { + await github.rest.issues.update({ + ...context.repo, + issue_number: pullRequest.number, + body: withoutManagedReference, + }); + } + return; + } + + const separator = withoutManagedReference ? '\n\n' : ''; + const updatedBody = `${withoutManagedReference}${separator}${marker}\nFixes #${issueNumber}\n`; + if (body !== updatedBody) { + await github.rest.issues.update({ + ...context.repo, + issue_number: pullRequest.number, + body: updatedBody, + }); + } diff --git a/ext/standard/tests/streams/stream_get_meta_data_socket_variation4.phpt b/ext/standard/tests/streams/stream_get_meta_data_socket_variation4.phpt index 14e1a6b38769..96eca440e4bc 100644 --- a/ext/standard/tests/streams/stream_get_meta_data_socket_variation4.phpt +++ b/ext/standard/tests/streams/stream_get_meta_data_socket_variation4.phpt @@ -4,10 +4,11 @@ Testing stream_get_meta_data() "eof" field on a udp socket bool(false) ["uri"]=> - string(21) "tcp://127.0.0.1:31334" + string(%d) "tcp://127.0.0.1:%d" } @@ -73,7 +74,7 @@ array(8) { ["seekable"]=> bool(false) ["uri"]=> - string(21) "tcp://127.0.0.1:31334" + string(%d) "tcp://127.0.0.1:%d" } @@ -94,5 +95,5 @@ array(8) { ["seekable"]=> bool(false) ["uri"]=> - string(21) "tcp://127.0.0.1:31334" + string(%d) "tcp://127.0.0.1:%d" }