Skip to content

Commit d5fd29d

Browse files
committed
(#146) Introduce the concept of IsPullRequest
Within GitHub, an issue and a pull request are essentially the same thing, at least in terms of how GRM uses them. However, in GitLab, they are uniquely different, and have their own unique numbers, where as in GitHub an issue or pull request just get the next number for the repository. So that we don't have to change too many things in GRM, let's introduce the concept of an IsPullRequest property to the issue model, that way the VcsProvider can provide this information if required, and then use the information to do the right thing when it comes to fetching and updating the information, but internally, GRM will just have a collection of issues, which it then acts on when required.
1 parent 57e1296 commit d5fd29d

File tree

6 files changed

+19
-3
lines changed

6 files changed

+19
-3
lines changed

src/GitReleaseManager.Core/MappingProfiles/GitHubProfile.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public GitHubProfile()
1010
CreateMap<Octokit.Issue, Model.Issue>()
1111
.ForMember(dest => dest.PublicNumber, act => act.MapFrom(src => src.Number))
1212
.ForMember(dest => dest.InternalNumber, act => act.MapFrom(src => src.Id))
13+
.ForMember(dest => dest.IsPullRequest, act => act.MapFrom(src => src.HtmlUrl.Contains("/pull/")))
1314
.ReverseMap();
1415
CreateMap<Model.IssueComment, Octokit.IssueComment>().ReverseMap();
1516
CreateMap<Model.ItemState, Octokit.ItemState>().ReverseMap();

src/GitReleaseManager.Core/Model/Issue.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ public sealed class Issue
1313
public string HtmlUrl { get; set; }
1414

1515
public IReadOnlyList<Label> Labels { get; set; }
16+
17+
public bool IsPullRequest { get; set; }
1618
}
1719
}

src/GitReleaseManager.Core/Provider/GitHubProvider.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,11 @@ public string GetMilestoneQueryString()
351351
return "closed=1";
352352
}
353353

354+
public string GetIssueType(Issue issue)
355+
{
356+
return issue.IsPullRequest ? "Pull Request" : "Issue";
357+
}
358+
354359
private async Task ExecuteAsync(Func<Task> action)
355360
{
356361
try

src/GitReleaseManager.Core/Provider/IVcsProvider.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,7 @@ public interface IVcsProvider
4747
RateLimit GetRateLimit();
4848

4949
string GetMilestoneQueryString();
50+
51+
string GetIssueType(Issue issue);
5052
}
5153
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
- [__#{{ issue.public_number }}__]({{ issue.html_url }}) {{ issue.title }}
1+
{{
2+
if issue.is_pull_request
3+
}}- [__!{{ issue.public_number }}__]({{ issue.html_url }}) {{ issue.title }}
4+
{{ else
5+
}}- [__#{{ issue.public_number }}__]({{ issue.html_url }}) {{ issue.title }}
6+
{{ end -}}

src/GitReleaseManager.Core/VcsService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,14 +383,15 @@ private async Task AddIssueCommentsAsync(string owner, string repository, Milest
383383

384384
try
385385
{
386+
var issueType = _vcsProvider.GetIssueType(issue);
386387
if (!await CommentsIncludeStringAsync(owner, repository, issue, detectionComment).ConfigureAwait(false))
387388
{
388-
_logger.Information("Adding release comment for issue #{IssueNumber}", issue.Number);
389+
_logger.Information("Adding release comment for {IssueType} #{IssueNumber}", issueType, issue.PublicNumber);
389390
await _vcsProvider.CreateIssueCommentAsync(owner, repository, issue, issueComment).ConfigureAwait(false);
390391
}
391392
else
392393
{
393-
_logger.Information("Issue #{IssueNumber} already contains release comment, skipping...", issue.Number);
394+
_logger.Information("{IssueType} #{IssueNumber} already contains release comment, skipping...", issueType, issue.PublicNumber);
394395
}
395396
}
396397
catch (ForbiddenException)

0 commit comments

Comments
 (0)