Skip to content

Commit

Permalink
Being able to navigate to a PR page of an AppVeyor build
Browse files Browse the repository at this point in the history
  • Loading branch information
pmiossec committed Mar 4, 2019
1 parent f63c836 commit 5cf47f0
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 2 deletions.
1 change: 1 addition & 0 deletions GitUI/GitUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -1844,6 +1844,7 @@
</ItemGroup>
<ItemGroup>
<None Include="Resources\Icons\DocumentTree.png" />
<None Include="Resources\Icons\pullRequest.png" />
<Content Include="Translation\Czech.gif">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down
10 changes: 10 additions & 0 deletions GitUI/Properties/Images.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions GitUI/Properties/Images.resx
Original file line number Diff line number Diff line change
Expand Up @@ -799,4 +799,7 @@
<data name="DocumentTree" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Icons\DocumentTree.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="PullRequest" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Icons\PullRequest.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
Binary file added GitUI/Resources/Icons/PullRequest.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 13 additions & 1 deletion GitUI/UserControls/RevisionGrid/RevisionGridControl.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions GitUI/UserControls/RevisionGrid/RevisionGridControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,8 @@ private void ContextMenuOpening(object sender, CancelEventArgs e)

SetEnabled(openBuildReportToolStripMenuItem, !string.IsNullOrWhiteSpace(revision.BuildStatus?.Url));

SetEnabled(openPullRequestPageStripMenuItem, !string.IsNullOrWhiteSpace(revision.BuildStatus?.PullRequestUrl));

RefreshOwnScripts();

UpdateSeparators();
Expand Down Expand Up @@ -2427,6 +2429,16 @@ private void openBuildReportToolStripMenuItem_Click(object sender, EventArgs e)
}
}

private void openPullRequestPageStripMenuItem_Click(object sender, EventArgs e)
{
var revision = GetSelectedRevisions().First();

if (!string.IsNullOrWhiteSpace(revision.BuildStatus?.PullRequestUrl))
{
Process.Start(revision.BuildStatus.PullRequestUrl);
}
}

private void editCommitToolStripMenuItem_Click(object sender, EventArgs e)
{
LaunchRebase("e");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,24 @@ private class Project
public string QueryUrl;
}

private string BuildPullRequetUrl(string repositoryType, string repositoryName, string pullRequestId)
{
switch (repositoryType)
{
case "bitBucket":
return $"https://bitbucket.org/{repositoryName}/pull-requests/{pullRequestId}";
case "gitHub":
return $"https://github.com/{repositoryName}/pull/{pullRequestId}";
case "gitLab":
return $"https://gitlab.com/{repositoryName}/merge_requests/{pullRequestId}";
case "vso":
case "git":
return null;
}

return null;
}

private IEnumerable<AppVeyorBuildInfo> QueryBuildsResults(Project project)
{
try
Expand All @@ -203,9 +221,13 @@ private IEnumerable<AppVeyorBuildInfo> QueryBuildsResults(Project project)
return Enumerable.Empty<AppVeyorBuildInfo>();
}
var builds = JObject.Parse(result)["builds"].Children();
var content = JObject.Parse(result);
var builds = content["builds"].Children();
var baseApiUrl = ApiBaseUrl + project.Id;
var baseWebUrl = WebSiteUrl + "/project/" + project.Id + "/build/";
var projectData = content["project"];
var repositoryName = projectData["repositoryName"];
var repositoryType = projectData["repositoryType"];
var buildDetails = new List<AppVeyorBuildInfo>();
foreach (var b in builds)
Expand Down Expand Up @@ -239,6 +261,7 @@ private IEnumerable<AppVeyorBuildInfo> QueryBuildsResults(Project project)
StartDate = b["started"]?.ToObject<DateTime>() ?? DateTime.MinValue,
BaseWebUrl = baseWebUrl,
Url = WebSiteUrl + "/project/" + project.Id + "/build/" + version,
PullRequestUrl = repositoryType != null && repositoryName != null && pullRequestId != null ? BuildPullRequetUrl(repositoryType.Value<string>(), repositoryName.Value<string>(), pullRequestId.Value<string>()) : null,
BaseApiUrl = baseApiUrl,
AppVeyorBuildReportUrl = baseApiUrl + "/build/" + version,
PullRequestText = pullRequestId != null ? "PR#" + pullRequestId.Value<string>() : string.Empty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ public enum BuildStatus
public string Url { get; set; }
public bool ShowInBuildReportTab { get; set; } = true;
public string Tooltip { get; set; }
public string PullRequestUrl { get; set; }
}
}

0 comments on commit 5cf47f0

Please sign in to comment.