mirror of
https://github.com/documize/community.git
synced 2025-07-23 07:09:43 +02:00
Fully working Jira connector using JQL
This commit is contained in:
parent
64b1394ec1
commit
4d1eb952b2
3 changed files with 37 additions and 26 deletions
File diff suppressed because one or more lines are too long
|
@ -50,12 +50,6 @@ func (*Provider) Meta() provider.TypeMeta {
|
||||||
|
|
||||||
// Render converts Jira data into HTML suitable for browser rendering.
|
// Render converts Jira data into HTML suitable for browser rendering.
|
||||||
func (p *Provider) Render(ctx *provider.Context, config, data string) string {
|
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{}
|
var c = jiraConfig{}
|
||||||
err := json.Unmarshal([]byte(config), &c)
|
err := json.Unmarshal([]byte(config), &c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -77,7 +71,7 @@ func (p *Provider) Render(ctx *provider.Context, config, data string) string {
|
||||||
|
|
||||||
issues, err := getIssues(c, client)
|
issues, err := getIssues(c, client)
|
||||||
|
|
||||||
return generateGrid(issues)
|
return generateGrid(creds.URL, issues)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh fetches latest issues list.
|
// 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.Header().Set("Content-Type", "html; charset=utf-8")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
w.Write([]byte(generateGrid(issues)))
|
w.Write([]byte(generateGrid(creds.URL, issues)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pull config from HTTP request.
|
// Pull config from HTTP request.
|
||||||
|
@ -259,13 +253,14 @@ func getIssues(config jiraConfig, client *jira.Client) (issues []jira.Issue, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate issues grid
|
// Generate issues grid
|
||||||
func generateGrid(issues []jira.Issue) string {
|
func generateGrid(jiraURL string, issues []jira.Issue) string {
|
||||||
t := template.New("issues")
|
t := template.New("issues")
|
||||||
t, _ = t.Parse(renderTemplate)
|
t, _ = t.Parse(renderTemplate)
|
||||||
|
|
||||||
payload := jiraGrid{}
|
payload := jiraGrid{}
|
||||||
payload.ItemCount = len(issues)
|
payload.ItemCount = len(issues)
|
||||||
payload.Issues = issues
|
payload.Issues = issues
|
||||||
|
payload.JiraURL = jiraURL
|
||||||
|
|
||||||
buffer := new(bytes.Buffer)
|
buffer := new(bytes.Buffer)
|
||||||
err := t.Execute(buffer, payload)
|
err := t.Execute(buffer, payload)
|
||||||
|
@ -289,10 +284,16 @@ type jiraLogin struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type jiraGrid struct {
|
type jiraGrid struct {
|
||||||
|
JiraURL string `json:"url"`
|
||||||
Issues []jira.Issue `json:"issues"`
|
Issues []jira.Issue `json:"issues"`
|
||||||
ItemCount int `json:"itemCount"`
|
ItemCount int `json:"itemCount"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type jiraFilter struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
JQL string `json:"jql"`
|
||||||
|
}
|
||||||
|
|
||||||
// the HTML that is rendered by this section.
|
// the HTML that is rendered by this section.
|
||||||
const renderTemplate = `
|
const renderTemplate = `
|
||||||
<p>{{.ItemCount}} items</p>
|
<p>{{.ItemCount}} items</p>
|
||||||
|
@ -303,23 +304,32 @@ const renderTemplate = `
|
||||||
<th class="bordered no-width">T</th>
|
<th class="bordered no-width">T</th>
|
||||||
<th class="bordered no-width">Status</th>
|
<th class="bordered no-width">Status</th>
|
||||||
<th class="bordered no-width">P</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">Summary</th>
|
||||||
<th class="bordered no-width">Assignee</th>
|
<th class="bordered no-width">Assignee</th>
|
||||||
<th class="bordered no-width">Fix Version/s</th>
|
<th class="bordered no-width">Fix Version/s</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
{{$app := .JiraURL}}
|
||||||
{{range $item := .Issues}}
|
{{range $item := .Issues}}
|
||||||
<tr>
|
<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"><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"><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.Summary }}</td>
|
||||||
<td class="bordered no-width">{{ $item.Fields.Assignee.DisplayName }}</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>
|
</tr>
|
||||||
{{end}}
|
{{end}}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
@ -11,21 +11,22 @@
|
||||||
<p>Your Documize administrator needs to provide Jira connection details before usage.</p>
|
<p>Your Documize administrator needs to provide Jira connection details before usage.</p>
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{#if authenticated}}
|
{{#if authenticated}}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
|
<form {{action 'onPreview'}}>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="gemini-url">Jira Query Language</label>
|
<label for="gemini-url">Jira Query Language</label>
|
||||||
{{focus-input id="jira-jql" type="text" value=config.jql class="form-control"}}
|
{{focus-input id="jira-jql" type="text" value=config.jql class="form-control" placeholder="e.g. (status = resolved AND project = SysAdmin) OR assignee = bobsmith"}}
|
||||||
<small class="form-text text-muted">Find issues using JQL</small>
|
|
||||||
</div>
|
</div>
|
||||||
<button class="btn btn-secondary font-weight-bold" {{action 'onPreview'}}>Preview</button>
|
<button type="submit" class="btn btn-secondary font-weight-bold">Preview</button>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row my-5">
|
<div class="row my-5">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
{{{issuesGrid}}}
|
{{{issuesGrid}}}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue