Skip to content
This repository was archived by the owner on Aug 10, 2022. It is now read-only.

Commit 725ba0b

Browse files
Handle PR Already Exists and Branch Already Exists Exceptions
1 parent 1ab7f15 commit 725ba0b

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

GitHubReadmeWebTrends.Functions/Functions/OpenPullRequestFunction.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,16 @@ public async Task Run([QueueTrigger(QueueConstants.OpenPullRequestQueue)] Reposi
2929

3030
log.LogInformation($"Forked Repository for {repository.Owner} {repository.Name}");
3131

32-
await CreateNewBranch(forkedRepository, branchName).ConfigureAwait(false);
32+
try
33+
{
34+
await CreateNewBranch(forkedRepository, branchName).ConfigureAwait(false);
3335

34-
log.LogInformation($"Create New Branch for {forkedRepository.Owner} {forkedRepository.Name}");
36+
log.LogInformation($"Creates New Branch for {forkedRepository.Owner} {forkedRepository.Name}");
37+
}
38+
catch (GraphQLException e) when (e.Errors.Any(x => x.Message.Contains("already exists", StringComparison.OrdinalIgnoreCase)))
39+
{
40+
log.LogInformation($"Existing Branch Found for {forkedRepository.Owner} {forkedRepository.Name}");
41+
}
3542

3643
await CommitUpdatedReadme(forkedRepository, branchName).ConfigureAwait(false);
3744

@@ -45,11 +52,11 @@ public async Task Run([QueueTrigger(QueueConstants.OpenPullRequestQueue)] Reposi
4552
}
4653
catch (ApiException e) when (e.StatusCode is System.Net.HttpStatusCode.Conflict)
4754
{
48-
//If a Pull Request with the same name is already open, GitHubGraphQLApiService.CreatePullRequest may return a 409 Conflict
55+
log.LogInformation($"Existing Pull Request Found for {forkedRepository.Owner} {forkedRepository.Name}");
4956
}
50-
catch (Exception e) when (e.Message.Contains("already exists", StringComparison.OrdinalIgnoreCase))
57+
catch (GraphQLException e) when (e.Errors.Any(x => x.Message.Contains("already exists", StringComparison.OrdinalIgnoreCase)))
5158
{
52-
//If a Pull Request with the same name is already open, GitHubGraphQLApiService.CreatePullRequest may return "A pull request already exists..."
59+
log.LogInformation($"Existing Pull Request Found for {forkedRepository.Owner} {forkedRepository.Name}");
5360
}
5461
}
5562

0 commit comments

Comments
 (0)