Skip to content
This repository was archived by the owner on Apr 26, 2020. It is now read-only.

Commit 53056fb

Browse files
vkrmsantonmedv
authored andcommitted
use try...catch (#219)
around `git-rev-list` to prevent from crashing
1 parent 1c93b31 commit 53056fb

1 file changed

Lines changed: 27 additions & 23 deletions

File tree

recipe/sentry.php

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ static function (&$value) use ($config) {
4848
) {
4949
throw new \RuntimeException(
5050
<<<EXAMPLE
51-
Required data missing. Please configure sentry:
51+
Required data missing. Please configure sentry:
5252
set(
53-
'sentry',
53+
'sentry',
5454
[
55-
'organization' => 'exampleorg',
55+
'organization' => 'exampleorg',
5656
'projects' => [
57-
'exampleproj',
57+
'exampleproj',
5858
'exampleproje2'
59-
],
60-
'token' => 'd47828...',
59+
],
60+
'token' => 'd47828...',
6161
]
6262
);"
6363
EXAMPLE
@@ -162,29 +162,33 @@ function getGitCommitsRefs(): Closure
162162
}
163163

164164
cd('{{release_path}}');
165-
$result = run(sprintf('git rev-list --pretty="%s" %s', 'format:%H#%an#%ae#%at', $commitRange));
166-
$lines = array_filter(
167-
// limit number of commits for first release with many commits
165+
try {
166+
$result = run(sprintf('git rev-list --pretty="%s" %s', 'format:%H#%an#%ae#%at', $commitRange));
167+
$lines = array_filter(
168+
// limit number of commits for first release with many commits
168169
array_map('trim', array_slice(explode("\n", $result), 0, 200)),
169170
static function (string $line): bool {
170-
return !empty($line) && strpos($line, 'commit') !== 0;
171+
return !empty($line) && strpos($line, 'commit') !== 0;
171172
}
172-
);
173-
173+
);
174174

175-
return array_map(
175+
return array_map(
176176
static function (string $line): array {
177-
[$ref, $authorName, $authorEmail, $timestamp] = explode('#', $line);
178-
179-
return [
180-
'id' => $ref,
181-
'author_name' => $authorName,
182-
'author_email' => $authorEmail,
183-
'timestamp' => date(DateTime::ATOM, (int) $timestamp),
184-
];
177+
[$ref, $authorName, $authorEmail, $timestamp] = explode('#', $line);
178+
179+
return [
180+
'id' => $ref,
181+
'author_name' => $authorName,
182+
'author_email' => $authorEmail,
183+
'timestamp' => date(DateTime::ATOM, (int) $timestamp),
184+
];
185185
},
186186
$lines
187-
);
187+
);
188+
189+
} catch (\Deployer\Exception\RuntimeException $e) {
190+
writeln($e->getMessage());
191+
return [];
192+
}
188193
};
189194
}
190-

0 commit comments

Comments
 (0)