Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE mothership.ExceptionStackTrace ADD COLUMN GitHubIssue INT;

ALTER TABLE mothership.ExceptionStackTrace RENAME COLUMN BugNumber TO LabKeyIssue;
7 changes: 6 additions & 1 deletion mothership/resources/schemas/mothership.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@
<fkDbSchema>core</fkDbSchema>
</fk>
</column>
<column columnName="BugNumber"/>
<column columnName="LabKeyIssue">
<columnTitle>LabKey Issue</columnTitle>
</column>
<column columnName="GitHubIssue">
<columnTitle>GitHub Issue</columnTitle>
</column>
<column columnName="Comments">
<inputRows>4</inputRows>
</column>
Expand Down
102 changes: 96 additions & 6 deletions mothership/src/org/labkey/mothership/CreateIssueDisplayColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,24 @@

package org.labkey.mothership;

import org.apache.commons.lang3.StringUtils;
import org.labkey.api.data.ActionButton;
import org.labkey.api.data.ColumnInfo;
import org.labkey.api.data.ConnectionWrapper;
import org.labkey.api.data.DataColumn;
import org.labkey.api.data.RenderContext;
import org.labkey.api.util.PageFlowUtil;
import org.labkey.api.util.UnexpectedException;
import org.labkey.api.view.HttpView;
import org.labkey.api.view.ViewServlet;
import org.labkey.api.writer.HtmlWriter;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

public class CreateIssueDisplayColumn extends DataColumn
{
private final ActionButton _saveButton;
Expand All @@ -39,11 +50,90 @@ public CreateIssueDisplayColumn(ColumnInfo column, ActionButton saveButton)
public void renderDetailsCellContents(RenderContext ctx, HtmlWriter out)
{
_saveButton.render(ctx, out);
out.write("\t");
PageFlowUtil.button("Create Issue")
.onClick("document.forms.CreateIssue.elements['AssignedTo'].value = document.forms[" +
PageFlowUtil.jsString(ctx.getCurrentRegion().getFormId()) +
"].elements['AssignedTo'].value; document.forms.CreateIssue.submit();")
.appendTo(out);

String repo = MothershipManager.get().getGitHubRepo();
if (!StringUtils.isEmpty(repo))
{
out.write("\t");

StringBuilder body = new StringBuilder();

body.append("Created from crash report: ");
body.append(HttpView.currentContext().getRequest().getAttribute(ViewServlet.ORIGINAL_URL_STRING));
body.append("\n\n");

StringBuilder title = new StringBuilder();
try
{
String stackTraceString = ctx.get(getBoundColumn().getFieldKey(), String.class);
BufferedReader reader = new BufferedReader(new StringReader(stackTraceString));
String firstLine = reader.readLine();
// Grab the exception class
String className = firstLine.split(":")[0];
if (className.lastIndexOf('.') != -1)
{
// Strip off the package name to make the title a little shorter
className = className.substring(className.lastIndexOf('.') + 1);
}
title.append(className);
body.append(firstLine);
String nextLine;
String separator = " in ";
String suffix = "";
String bestLocation = null;
String firstLocation = null;
while ((nextLine = reader.readLine()) != null)
{
if (firstLocation == null)
{
firstLocation = nextLine;
}
if (bestLocation == null &&
((nextLine.contains("org.labkey") && !nextLine.contains(ConnectionWrapper.class.getPackage().getName())) ||
nextLine.contains("org.fhcrc")))
{
bestLocation = nextLine;
separator = " from ";
}

if (body.length() + nextLine.length() < 6000) // Don't exceed GitHub's GET URL limit
{
body.append(nextLine);
body.append("\n");
}
else
{
suffix = "...\n";
}
}
body.append(suffix);

if (bestLocation == null)
{
bestLocation = firstLocation;
}
if (bestLocation != null)
{
bestLocation = bestLocation.trim();
if (bestLocation.startsWith("at "))
{
bestLocation = bestLocation.substring("at ".length());
}
title.append(separator);
title.append(bestLocation.split("\\(")[0]);
title.append("()");
}
}
catch (IOException e)
{
throw UnexpectedException.wrap(e);
}

String url = "https://github.com/LabKey/" + repo + "/issues/new?title=" +
URLEncoder.encode(title.toString(), StandardCharsets.UTF_8) +
"&body=" + URLEncoder.encode(body.toString(), StandardCharsets.UTF_8);

PageFlowUtil.button("Create Issue").target("_blank").href(url).appendTo(out);
}
}
}
21 changes: 16 additions & 5 deletions mothership/src/org/labkey/mothership/ExceptionStackTrace.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public class ExceptionStackTrace
private String _stackTrace;
private String _stackTraceHash;
private Integer _assignedTo;
private Integer _bugNumber;
private Integer _labkeyIssue;
private Integer _githubIssue;
private String _comments;
private Date _modified;
private User _modifiedBy;
Expand Down Expand Up @@ -94,14 +95,24 @@ public void setAssignedTo(Integer assignedTo)
_assignedTo = assignedTo;
}

public Integer getBugNumber()
public Integer getLabKeyIssue()
{
return _bugNumber;
return _labkeyIssue;
}

public void setBugNumber(Integer bugNumber)
public void setLabKeyIssue(Integer labkeyIssue)
{
_bugNumber = bugNumber;
_labkeyIssue = labkeyIssue;
}

public Integer getGithubIssue()
{
return _githubIssue;
}

public void setGithubIssue(Integer githubIssue)
{
_githubIssue = githubIssue;
}

public String getComments()
Expand Down
65 changes: 65 additions & 0 deletions mothership/src/org/labkey/mothership/IssueDisplayColumn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.labkey.mothership;

import org.labkey.api.data.ColumnInfo;
import org.labkey.api.data.ContainerManager;
import org.labkey.api.data.DataColumn;
import org.labkey.api.data.RenderContext;
import org.labkey.api.issues.IssuesUrls;
import org.labkey.api.query.FieldKey;
import org.labkey.api.util.PageFlowUtil;
import org.labkey.api.view.ActionURL;

import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

import java.util.Set;

public class IssueDisplayColumn extends DataColumn
{
public IssueDisplayColumn(ColumnInfo col)
{
super(col);
}

@Override
public String renderURL(RenderContext ctx)
{
Integer gitHubIssue = ctx.get(getGitHubIssueFieldKey(), Integer.class);
if (gitHubIssue != null)
{
String repo = MothershipManager.get().getGitHubRepo();
return String.format("https://github.com/LabKey/%s/issues/%d", URLEncoder.encode(repo, StandardCharsets.UTF_8), gitHubIssue);
}
Integer labkeyIssue = ctx.get(getLabKeyIssueFieldKey(), Integer.class);
if (labkeyIssue != null)
{
String path = MothershipManager.get().getIssuesContainer();
if (path != null)
{
ActionURL url = PageFlowUtil.urlProvider(IssuesUrls.class).getDetailsURL(ContainerManager.getForPath(path));
url.addParameter("issueId", labkeyIssue);
return url.getLocalURIString();
}
}

return super.renderURL(ctx);
}

@Override
public void addQueryFieldKeys(Set<FieldKey> keys)
{
super.addQueryFieldKeys(keys);
keys.add(getGitHubIssueFieldKey());
keys.add(getLabKeyIssueFieldKey());
}

private FieldKey getGitHubIssueFieldKey()
{
return FieldKey.fromString(getBoundColumn().getFieldKey().getParent(), "GitHubIssue");
}

private FieldKey getLabKeyIssueFieldKey()
{
return FieldKey.fromString(getBoundColumn().getFieldKey().getParent(), "LabKeyIssue");
}
}
Loading
Loading