Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions .github/workflows/link-pull-request-issues.yml
Original file line number Diff line number Diff line change
@@ -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 = '<!-- php-src-issue-link -->';
const withoutManagedReference = body
.replace(/\n?<!-- php-src-issue-link -->\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,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ Testing stream_get_meta_data() "eof" field on a udp socket
<?php

/* Setup socket server */
$server = stream_socket_server('tcp://127.0.0.1:31334');
$server = stream_socket_server('tcp://127.0.0.1:0');
$address = stream_socket_get_name($server, false);

/* Connect to it */
$client = fsockopen('tcp://127.0.0.1:31334');
$client = fsockopen("tcp://$address");
if (!$client) {
die("Unable to create socket");
}
Expand Down Expand Up @@ -52,7 +53,7 @@ array(8) {
["seekable"]=>
bool(false)
["uri"]=>
string(21) "tcp://127.0.0.1:31334"
string(%d) "tcp://127.0.0.1:%d"
}


Expand All @@ -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"
}


Expand All @@ -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"
}
Loading