1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-22 22:59:43 +02:00

Fully working Jira connector using JQL

This commit is contained in:
HarveyKandola 2018-08-08 12:18:04 +01:00
parent 64b1394ec1
commit 4d1eb952b2
3 changed files with 37 additions and 26 deletions

File diff suppressed because one or more lines are too long

View file

@ -50,12 +50,6 @@ func (*Provider) Meta() provider.TypeMeta {
// Render converts Jira data into HTML suitable for browser rendering.
func (p *Provider) Render(ctx *provider.Context, config, data string) string {
// issues := []jira.Issue{}
// var c = jiraConfig{}
// json.Unmarshal([]byte(data), &issues)
// json.Unmarshal([]byte(config), &c)
var c = jiraConfig{}
err := json.Unmarshal([]byte(config), &c)
if err != nil {
@ -77,7 +71,7 @@ func (p *Provider) Render(ctx *provider.Context, config, data string) string {
issues, err := getIssues(c, client)
return generateGrid(issues)
return generateGrid(creds.URL, issues)
}
// Refresh fetches latest issues list.
@ -203,7 +197,7 @@ func previewGrid(ctx *provider.Context, store *domain.Store, w http.ResponseWrit
w.Header().Set("Content-Type", "html; charset=utf-8")
w.WriteHeader(http.StatusOK)
w.Write([]byte(generateGrid(issues)))
w.Write([]byte(generateGrid(creds.URL, issues)))
}
// Pull config from HTTP request.
@ -259,13 +253,14 @@ func getIssues(config jiraConfig, client *jira.Client) (issues []jira.Issue, err
}
// Generate issues grid
func generateGrid(issues []jira.Issue) string {
func generateGrid(jiraURL string, issues []jira.Issue) string {
t := template.New("issues")
t, _ = t.Parse(renderTemplate)
payload := jiraGrid{}
payload.ItemCount = len(issues)
payload.Issues = issues
payload.JiraURL = jiraURL
buffer := new(bytes.Buffer)
err := t.Execute(buffer, payload)
@ -289,10 +284,16 @@ type jiraLogin struct {
}
type jiraGrid struct {
JiraURL string `json:"url"`
Issues []jira.Issue `json:"issues"`
ItemCount int `json:"itemCount"`
}
type jiraFilter struct {
Name string `json:"name"`
JQL string `json:"jql"`
}
// the HTML that is rendered by this section.
const renderTemplate = `
<p>{{.ItemCount}} items</p>
@ -303,23 +304,32 @@ const renderTemplate = `
<th class="bordered no-width">T</th>
<th class="bordered no-width">Status</th>
<th class="bordered no-width">P</th>
<th class="bordered no-width">Component</th>
<th class="bordered no-width">Component/s</th>
<th class="bordered">Summary</th>
<th class="bordered no-width">Assignee</th>
<th class="bordered no-width">Fix Version/s</th>
</tr>
</thead>
<tbody>
{{range $item := .Issues}}
{{$app := .JiraURL}}
{{range $item := .Issues}}
<tr>
<td class="bordered no-width"><a href="{{ $item.Self }}">{{ $item.Key }}</a></td>
<td class="bordered no-width"><a href="{{ $app }}/browse/{{ $item.Key }}">{{ $item.Key }}</a></td>
<td class="bordered no-width"><img class="section-jira-icon" src='{{ $item.Fields.Type.IconURL }}' /></td>
<td class="bordered no-width">{{ $item.Fields.Status.Name }}</td>
<td class="bordered no-width"><span class="badge badge-warning">{{ $item.Fields.Status.Name }}</span></td>
<td class="bordered no-width"><img class="section-jira-icon" src='{{ $item.Fields.Priority.IconURL }}' /></td>
<td class="bordered no-width"></td>
<td class="bordered no-width">
{{range $comp := $item.Fields.Components}}
{{ $comp.Name }}
{{end}}
</td>
<td class="bordered no-width">{{ $item.Fields.Summary }}</td>
<td class="bordered no-width">{{ $item.Fields.Assignee.DisplayName }}</td>
<td class="bordered no-width"></td>
<td class="bordered no-width">
{{range $ver := $item.Fields.FixVersions}}
{{ $ver.Name }}
{{end}}
</td>
</tr>
{{end}}
</tbody>

View file

@ -11,21 +11,22 @@
<p>Your Documize administrator needs to provide Jira connection details before usage.</p>
{{/unless}}
{{/if}}
</div>
</div>
{{#if authenticated}}
<div class="row">
<div class="col-12">
<div class="form-group">
<label for="gemini-url">Jira Query Language</label>
{{focus-input id="jira-jql" type="text" value=config.jql class="form-control"}}
<small class="form-text text-muted">Find issues using JQL</small>
</div>
<button class="btn btn-secondary font-weight-bold" {{action 'onPreview'}}>Preview</button>
<form {{action 'onPreview'}}>
<div class="form-group">
<label for="gemini-url">Jira Query Language</label>
{{focus-input id="jira-jql" type="text" value=config.jql class="form-control" placeholder="e.g. (status = resolved AND project = SysAdmin) OR assignee = bobsmith"}}
</div>
<button type="submit" class="btn btn-secondary font-weight-bold">Preview</button>
</form>
</div>
</div>
<div class="row my-5">
<div class="col-12">
{{{issuesGrid}}}