diff --git a/src/comments.js b/src/comments.js index b0343f9..ec9e084 100644 --- a/src/comments.js +++ b/src/comments.js @@ -9,10 +9,13 @@ class Comments { constructor(client, owner, repo, builds) { this.gh = client this.db = builds - this.nj = nunjucks.configure() - this.template = template this.repo = repo /* name of repo to query */ this.owner = owner /* name of user who makes the comments */ + /* setup templating for comments */ + this.template = template + this.nj = new nunjucks.Environment() + /* add helper for formatting dates */ + this.nj.addFilter('date', (data) => (new Date(data)).toLocaleTimeString('utc')) } async listComments (pr, per_page = PER_PAGE, sort = 'updated', direction = 'desc') { diff --git a/src/template.js b/src/template.js index c948c67..d304f3e 100644 --- a/src/template.js +++ b/src/template.js @@ -4,9 +4,9 @@ module.exports = ` |-|-|-|-|-|-|-| {% for b in builds -%} {%- if b.success -%} -| :heavy_check_mark: | {{ b.commit }} | {{ b.meta.created }} | \`{{ b.platform }}\` | [{{ b.pr }}#{{ b.id }}]({{ b.url }}) | {{ b.duration }} | [:package: {{ b.platform }}]({{ b.pkg_url }}) | +| :heavy_check_mark: | {{ b.commit }} | {{ b.meta.created | date }} | \`{{ b.platform }}\` | [#{{ b.id }}]({{ b.url }}) | {{ b.duration }} | [:package: {{ b.platform }}]({{ b.pkg_url }}) | {% else -%} -| :x: | {{ b.commit }} | {{ b.meta.created }} | \`{{ b.platform }}\` | [{{ b.pr }}#{{ b.id }}]({{ b.url }}) | {{ b.duration }} | [:page_facing_up: build log]({{ b.pkg_url }}consoleText) | +| :x: | {{ b.commit }} | {{ b.meta.created | date }} | \`{{ b.platform }}\` | [#{{ b.id }}]({{ b.url }}) | {{ b.duration }} | [:page_facing_up: build log]({{ b.pkg_url }}consoleText) | {% endif -%} {%- endfor -%} `