From 76e9e727eee7fecedb7dbdca9e7de7ecc68c43fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Thu, 13 Dec 2018 00:36:43 +0100 Subject: [PATCH] add formatting of meta.created with Date object MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- src/comments.js | 7 +++++-- src/template.js | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) 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 -%} `