Skip to content

Commit

Permalink
(#146) Extend issue with an internal number
Browse files Browse the repository at this point in the history
Similar to the last commit for extending the milestone model to have a
internal number, we need to do the same thing with the issue model.
This is due to the fact that GitLab has both an "internal" and "public"
Id for the issue.
  • Loading branch information
gep13 committed Sep 26, 2023
1 parent 4213dce commit eca8e33
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class GitHubProviderTests
private const bool SKIP_PRERELEASES = false;

private readonly Release _release = new Release { Id = RELEASE_ID };
private readonly Issue _issue = new Issue { Number = ISSUE_NUMBER };
private readonly Issue _issue = new Issue { PublicNumber = ISSUE_NUMBER };
private readonly Milestone _milestone = new Milestone { PublicNumber = MILESTONE_PUBLIC_NUMBER, InternalNumber = MILESTONE_INTERNAL_NUMBER };
private readonly Label _label = new Label { Name = LABEL_NAME };
private readonly ReleaseAsset _asset = new ReleaseAsset { Id = ASSET_ID };
Expand Down
5 changes: 4 additions & 1 deletion src/GitReleaseManager.Core/MappingProfiles/GitHubProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ public class GitHubProfile : Profile
{
public GitHubProfile()
{
CreateMap<Model.Issue, Octokit.Issue>().ReverseMap();
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))
.ReverseMap();
CreateMap<Model.IssueComment, Octokit.IssueComment>().ReverseMap();
CreateMap<Model.ItemState, Octokit.ItemState>().ReverseMap();
CreateMap<Model.ItemStateFilter, Octokit.ItemStateFilter>().ReverseMap();
Expand Down
4 changes: 3 additions & 1 deletion src/GitReleaseManager.Core/Model/Issue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ public sealed class Issue
{
public string Title { get; set; }

public int Number { get; set; }
public int InternalNumber { get; set; }

public int PublicNumber { get; set; }

public string HtmlUrl { get; set; }

Expand Down
4 changes: 2 additions & 2 deletions src/GitReleaseManager.Core/Provider/GitHubProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public Task CreateIssueCommentAsync(string owner, string repository, Issue issue
{
return ExecuteAsync(async () =>
{
await _gitHubClient.Issue.Comment.Create(owner, repository, issue.Number, comment).ConfigureAwait(false);
await _gitHubClient.Issue.Comment.Create(owner, repository, issue.PublicNumber, comment).ConfigureAwait(false);
});
}

Expand Down Expand Up @@ -132,7 +132,7 @@ public Task<IEnumerable<IssueComment>> GetIssueCommentsAsync(string owner, strin
do
{
var options = GetApiOptions(startPage);
results = await _gitHubClient.Issue.Comment.GetAllForIssue(owner, repository, issue.Number, options).ConfigureAwait(false);
results = await _gitHubClient.Issue.Comment.GetAllForIssue(owner, repository, issue.PublicNumber, options).ConfigureAwait(false);

comments.AddRange(results);
startPage++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private Dictionary<string, List<Issue>> GetIssuesDict(List<Issue> issues)
.Where(o => issueLabels.Any(il => string.Equals(il, o.Label, StringComparison.OrdinalIgnoreCase)))
.GroupBy(o => o.Label, o => o.Issue)
.OrderBy(o => o.Key)
.ToDictionary(o => GetValidLabel(o.Key, o.Count()), o => o.OrderBy(issue => issue.Number).ToList());
.ToDictionary(o => GetValidLabel(o.Key, o.Count()), o => o.OrderBy(issue => issue.PublicNumber).ToList());

return issuesByLabel;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- [__#{{ issue.number }}__]({{ issue.html_url }}) {{ issue.title }}
- [__#{{ issue.public_number }}__]({{ issue.html_url }}) {{ issue.title }}
4 changes: 2 additions & 2 deletions src/GitReleaseManager.Core/VcsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,15 +395,15 @@ private async Task AddIssueCommentsAsync(string owner, string repository, Milest
}
catch (ForbiddenException)
{
_logger.Error("Unable to add comment to issue #{IssueNumber}. Insufficient permissions.", issue.Number);
_logger.Error("Unable to add comment to issue #{IssueNumber}. Insufficient permissions.", issue.PublicNumber);
break;
}
}
}

private async Task<bool> CommentsIncludeStringAsync(string owner, string repository, Issue issue, string comment)
{
_logger.Verbose("Finding issue comment created by GitReleaseManager for issue #{IssueNumber}", issue.Number);
_logger.Verbose("Finding issue comment created by GitReleaseManager for issue #{IssueNumber}", issue.PublicNumber);
var issueComments = await _vcsProvider.GetIssueCommentsAsync(owner, repository, issue).ConfigureAwait(false);

return issueComments.Any(c => c.Body.Contains(comment));
Expand Down
2 changes: 1 addition & 1 deletion src/GitReleaseManager.Tests/ReleaseNotesBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private static Issue CreateIssue(int number, params string[] labels)
{
return new Issue
{
Number = number,
PublicNumber = number,
Labels = labels.Select(l => new Label { Name = l }).ToList(),
HtmlUrl = "http://example.com/" + number,
Title = "Issue " + number,
Expand Down

0 comments on commit eca8e33

Please sign in to comment.