Skip to content

Commit

Permalink
Merge fc28f29 into fe8ce17
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksm committed Feb 8, 2021
2 parents fe8ce17 + fc28f29 commit c133729
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
}
},
"scripts": {
"phpstan": "phpstan analyse src test --level=2 -c phpstan.neon",
"phpstan": "phpstan analyse src test",
"test": "@composer lint && phpunit",
"lint": "phpcs -p -n"
}
Expand Down
7 changes: 4 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
parameters:
excludes_analyse:
- %rootDir%/../../../src/ProviderFactory.php
- %rootDir%/../../../src/Providers/Bitbucket.php
level: 2
excludes_analyse:
- %rootDir%/../../../src/ProviderFactory.php
- %rootDir%/../../../src/Providers/Bitbucket.php
28 changes: 26 additions & 2 deletions src/CosyComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,8 @@ protected function handleIndividualUpdates($data, $lockdata, $cdata, $one_pr_per
}
$security_update = false;
$package_name = $item->name;
$branch_name = '';
$pr_params = [];
try {
$pre_update_data = $this->getPackageData($package_name, $lockdata);
$version_from = $item->version;
Expand Down Expand Up @@ -1235,13 +1237,13 @@ protected function handleIndividualUpdates($data, $lockdata, $cdata, $one_pr_per
} catch (ValidationFailedException $e) {
// @todo: Do some better checking. Could be several things, this.
$this->log('Had a problem with creating the pull request: ' . $e->getMessage(), 'error');
if (isset($branch_name) && isset($pr_params) && !empty($prs_named[$branch_name]['title']) && $prs_named[$branch_name]['title'] != $pr_params['title']) {
if ($this->shouldUpdatePr($branch_name, $pr_params, $prs_named)) {
$this->log('Will try to update the PR.');
$this->getPrClient()->updatePullRequest($this->slug, $prs_named[$branch_name]['number'], $pr_params);
}
} catch (\Gitlab\Exception\RuntimeException $e) {
$this->log('Had a problem with creating the pull request: ' . $e->getMessage(), 'error');
if (isset($branch_name) && isset($pr_params) && !empty($prs_named[$branch_name]['title']) && $prs_named[$branch_name]['title'] != $pr_params['title']) {
if ($this->shouldUpdatePr($branch_name, $pr_params, $prs_named)) {
$this->log('Will try to update the PR based on settings.');
$this->getPrClient()->updatePullRequest($this->slug, $prs_named[$branch_name]['number'], $pr_params);
}
Expand Down Expand Up @@ -1276,6 +1278,28 @@ protected function handleIndividualUpdates($data, $lockdata, $cdata, $one_pr_per
}
}

/**
* Helper function.
*/
protected function shouldUpdatePr($branch_name, $pr_params, $prs_named)
{
if (empty($branch_name)) {
return false;
}
if (empty($pr_params)) {
return false;
}
if (!empty($prs_named[$branch_name]['title']) && $prs_named[$branch_name]['title'] != $pr_params['title']) {
return true;
}
if (!empty($prs_named[$branch_name]['body']) && !empty($pr_params['body'])) {
if (trim($prs_named[$branch_name]['body']) != trim($pr_params['body'])) {
return true;
}
}
return false;
}

/**
* Get the messages that are logged.
*
Expand Down
1 change: 1 addition & 0 deletions src/Providers/Gitlab.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public function getPrsNamed(Slug $slug)
]);
$prs_named[$pr['source_branch']] = [
'title' => $pr['title'],
'body' => !empty($pr['description']) ? $pr['description'] : '',
'number' => $pr["iid"],
'base' => [
'sha' => !empty($commits[1]["id"]) ? $commits[1]["id"] : $pr['sha'],
Expand Down

0 comments on commit c133729

Please sign in to comment.