Skip to content

Commit

Permalink
Use pull request title for autosynth PRs (#1405)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdpedrie authored and dwsupplee committed Nov 7, 2018
1 parent d97deac commit 9453026
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions dev/src/ReleaseBuilder/ReleaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ReleaseBuilder extends GoogleCloudCommand
const TARGET_REGEX = '/([a-zA-Z0-9-_]{1,})\/([a-zA-Z0-9-_]{1,})\.git/';

const GITHUB_RELEASES_ENDPOINT = 'https://api.github.com/repos/%s/%s/releases/tags/%s';
const GITHUB_PULL_ENDPOINT = 'https://api.github.com/repos/%s/%s/pulls/%s';
const GITHUB_COMPARE_ENDPOINT = 'https://api.github.com/repos/%s/%s/compare/%s...master';

CONST LEVEL_PATCH = 0;
Expand Down Expand Up @@ -672,18 +673,41 @@ private function getCommits($org, $repo, $version)
$description = explode("\n", $message)[0];
$matches = [];
preg_match('/(.{0,})\(\#(\d{1,})\)/', $description, $matches);
$message = trim($matches[1]);
$prNumber = isset($matches[2]) ? $matches[2] : null;

if (strpos($message, '[CHANGE ME]') === 0 && $prNumber) {
$message = $this->getMessageFromPullRequest($org, $repo, $prNumber);
}

$commits[] = [
'url' => $commit['url'],
'htmlUrl' => $commit['html_url'],
'message' => trim($matches[1]),
'reference' => $matches[2],
'message' => $message,
'reference' => $prNumber,
'hash' => $commit['sha']
];
}

return $commits;
}

private function getMessageFromPullRequest($org, $repo, $prNumber)
{
$url = sprintf(
self::GITHUB_PULL_ENDPOINT,
$org,
$repo,
$prNumber
);

$res = json_decode($this->http->get($url, [
'auth' => [null, $this->token]
])->getBody(), true);

return $res['title'];
}

/**
* Query the github API for a list of files modified by a commit.
*
Expand Down

0 comments on commit 9453026

Please sign in to comment.