Skip to content

Commit

Permalink
(#146) Introduce the concept of IsPullRequest
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gep13 committed Oct 4, 2023
1 parent dd6a51e commit 90a12f7
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public GitHubProfile()
CreateMap<Octokit.Issue, Model.Issue>()
.ForMember(dest => dest.PublicNumber, act => act.MapFrom(src => src.Number))
.ForMember(dest => dest.InternalNumber, act => act.MapFrom(src => src.Id))
.ForMember(dest => dest.IsPullRequest, act => act.MapFrom(src => src.HtmlUrl.Contains("/pull/")))
.ReverseMap();
CreateMap<Model.IssueComment, Octokit.IssueComment>().ReverseMap();
CreateMap<Model.ItemState, Octokit.ItemState>().ReverseMap();
Expand Down
2 changes: 2 additions & 0 deletions src/GitReleaseManager.Core/Model/Issue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ public sealed class Issue
public string HtmlUrl { get; set; }

public IReadOnlyList<Label> Labels { get; set; }

public bool IsPullRequest { get; set; }
}
}
5 changes: 5 additions & 0 deletions src/GitReleaseManager.Core/Provider/GitHubProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,11 @@ public string GetMilestoneQueryString()
return "closed=1";
}

public string GetIssueType(Issue issue)
{
return issue.IsPullRequest ? "Pull Request" : "Issue";
}

private async Task ExecuteAsync(Func<Task> action)
{
try
Expand Down
2 changes: 2 additions & 0 deletions src/GitReleaseManager.Core/Provider/IVcsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@ public interface IVcsProvider
RateLimit GetRateLimit();

string GetMilestoneQueryString();

string GetIssueType(Issue issue);
}
}
7 changes: 6 additions & 1 deletion src/GitReleaseManager.Core/Templates/default/issue-note.sbn
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
- [__#{{ issue.public_number }}__]({{ issue.html_url }}) {{ issue.title }}
{{
if issue.is_pull_request
}}- [__!{{ issue.public_number }}__]({{ issue.html_url }}) {{ issue.title }}
{{ else
}}- [__#{{ issue.public_number }}__]({{ issue.html_url }}) {{ issue.title }}
{{ end -}}
5 changes: 3 additions & 2 deletions src/GitReleaseManager.Core/VcsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,15 @@ private async Task AddIssueCommentsAsync(string owner, string repository, Milest

try
{
var issueType = _vcsProvider.GetIssueType(issue);
if (!await CommentsIncludeStringAsync(owner, repository, issue, detectionComment).ConfigureAwait(false))
{
_logger.Information("Adding release comment for issue #{IssueNumber}", issue.Number);
_logger.Information("Adding release comment for {IssueType} #{IssueNumber}", issueType, issue.PublicNumber);
await _vcsProvider.CreateIssueCommentAsync(owner, repository, issue, issueComment).ConfigureAwait(false);
}
else
{
_logger.Information("Issue #{IssueNumber} already contains release comment, skipping...", issue.Number);
_logger.Information("{IssueType} #{IssueNumber} already contains release comment, skipping...", issueType, issue.PublicNumber);
}
}
catch (ForbiddenException)
Expand Down

0 comments on commit 90a12f7

Please sign in to comment.