aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/assets/js/admin/dialogs/project-edit.js6
-rw-r--r--data/init.yaml31
-rw-r--r--src/guff/apis.cr11
-rw-r--r--src/guff/models/blog.cr17
-rw-r--r--src/guff/models/page.cr17
-rw-r--r--src/guff/models/post.cr16
-rw-r--r--src/guff/models/project.cr45
7 files changed, 73 insertions, 70 deletions
diff --git a/data/assets/js/admin/dialogs/project-edit.js b/data/assets/js/admin/dialogs/project-edit.js
index 8df9364..bfb7334 100644
--- a/data/assets/js/admin/dialogs/project-edit.js
+++ b/data/assets/js/admin/dialogs/project-edit.js
@@ -7,6 +7,8 @@ jQuery(function($) {
var r = ev.post_data;
$(p + 'repo').val(r.repo_url);
+ $(p + 'tag-prefix').val(r.tag_prefix);
+ $(p + 'secret').val(r.hook_secret);
});
$(p + 'confirm').click(function() {
@@ -14,7 +16,9 @@ jQuery(function($) {
type: 'guff.save',
post_data: {
- repo_url: $(p + 'repo').val(),
+ repo_url: $(p + 'repo').val(),
+ tag_prefix: $(p + 'tag-prefix').val(),
+ hook_secret: $(p + 'secret').val(),
},
});
diff --git a/data/init.yaml b/data/init.yaml
index 46a1e11..34a0595 100644
--- a/data/init.yaml
+++ b/data/init.yaml
@@ -272,7 +272,9 @@ init_sql:
REFERENCES states(state_id),
posted_at TIMESTAMP WITH TIME ZONE,
- expires_at TIMESTAMP WITH TIME ZONE,
+
+ -- TODO: add window for visibility
+ -- expires_at TIMESTAMP WITH TIME ZONE,
name TEXT NOT NULL DEFAULT '',
@@ -307,8 +309,33 @@ init_sql:
post_id INTEGER PRIMARY KEY
REFERENCES posts(post_id),
+ -- repository url
repo_url TEXT NOT NULL DEFAULT ''
- CHECK (repo_url NOT LIKE '% %')
+ CHECK (repo_url NOT LIKE '% %'),
+
+ -- prefix to strip from release tags
+ tag_prefix TEXT NOT NULL DEFAULT ''
+ CHECK (tag_prefix NOT LIKE '% %'),
+
+ -- secret string used for hooks
+ hook_secret TEXT NOT NULL DEFAULT ''
+ CHECK (hook_secret NOT LIKE '% %')
+ )
+
+ - |
+ CREATE TABLE project_releases (
+ post_id INTEGER NOT NULL
+ REFERENCES posts(post_id),
+
+ name TEXT NOT NULL CHECK (
+ LENGTH(name) > 0 AND
+ name NOT LIKE '% %'
+ ),
+
+ created_at TIMESTAMP WITH TIME ZONE
+ NOT NULL DEFAULT CURRENT_TIMESTAMP,
+
+ PRIMARY KEY (post_id, name)
)
- |
diff --git a/src/guff/apis.cr b/src/guff/apis.cr
index 874f354..5d87af2 100644
--- a/src/guff/apis.cr
+++ b/src/guff/apis.cr
@@ -32,9 +32,6 @@ module Guff::APIs
have_posted_at: !!params["posted_at"]?,
posted_at: params["posted_at"]? ? ISO8601.parse(params["posted_at"]) : nil,
- have_expires_at: !!params["expires_at"]?,
- expires_at: params["expires_at"]? ? ISO8601.parse(params["expires_at"]) : nil,
-
slug: params["slug"]?,
slug_lock: params["slug_lock"]? ? (params["slug_lock"] == "t") : nil,
@@ -78,9 +75,6 @@ module Guff::APIs
have_posted_at: !!params["posted_at"]?,
posted_at: params["posted_at"]? ? ISO8601.parse(params["posted_at"]) : nil,
- have_expires_at: !!params["expires_at"]?,
- expires_at: params["expires_at"]? ? ISO8601.parse(params["expires_at"]) : nil,
-
slug: params["slug"]?,
slug_lock: params["slug_lock"]? ? (params["slug_lock"] == "t") : nil,
@@ -88,6 +82,8 @@ module Guff::APIs
body: params["body"]?,
repo_url: params["repo_url"]?,
+ tag_prefix: params["tag_prefix"]?,
+ hook_secret: params["hook_secret"]?,
)
nil
@@ -127,9 +123,6 @@ module Guff::APIs
have_posted_at: !!params["posted_at"]?,
posted_at: params["posted_at"]? ? ISO8601.parse(params["posted_at"]) : nil,
- have_expires_at: !!params["expires_at"]?,
- expires_at: params["expires_at"]? ? ISO8601.parse(params["expires_at"]) : nil,
-
slug: params["slug"]?,
slug_lock: params["slug_lock"]? ? (params["slug_lock"] == "t") : nil,
diff --git a/src/guff/models/blog.cr b/src/guff/models/blog.cr
index 15a3188..bb35401 100644
--- a/src/guff/models/blog.cr
+++ b/src/guff/models/blog.cr
@@ -17,9 +17,8 @@ class Guff::Models::BlogModel < Guff::Models::Model
WHERE a.site_id = ?
AND d.state = 'public'
- AND (0 + strftime('%%s'))
- BETWEEN (0 + strftime('%%s', COALESCE(b.posted_at, 'now')))
- AND (0 + strftime('%%s', COALESCE(b.expires_at,'now')))
+ AND (0 + strftime('%%s')) >=
+ (0 + strftime('%%s', COALESCE(b.posted_at, 'now')))
AND %s
",
@@ -46,9 +45,8 @@ class Guff::Models::BlogModel < Guff::Models::Model
WHERE a.site_id = ?
AND d.state = 'public'
- AND (0 + strftime('%%s'))
- BETWEEN (0 + strftime('%%s', COALESCE(b.posted_at, 'now')))
- AND (0 + strftime('%%s', COALESCE(b.expires_at,'now')))
+ AND (0 + strftime('%%s')) >=
+ (0 + strftime('%%s', COALESCE(b.posted_at, 'now')))
AND %s
ORDER BY COALESCE(b.posted_at, b.created_at) DESC
@@ -61,7 +59,6 @@ class Guff::Models::BlogModel < Guff::Models::Model
a.site_id,
c.state,
a.posted_at,
- a.expires_at,
a.slug,
a.slug_lock,
a.name,
@@ -195,9 +192,6 @@ class Guff::Models::BlogModel < Guff::Models::Model
have_posted_at : Bool = false,
posted_at : Time? = nil,
- have_expires_at : Bool = false,
- expires_at : Time? = nil,
-
slug : String? = nil,
slug_lock : Bool? = nil,
@@ -215,9 +209,6 @@ class Guff::Models::BlogModel < Guff::Models::Model
have_posted_at: have_posted_at,
posted_at: posted_at,
- have_expires_at: have_expires_at,
- expires_at: expires_at,
-
slug: slug,
slug_lock: slug_lock,
diff --git a/src/guff/models/page.cr b/src/guff/models/page.cr
index 6cca2be..b7043a4 100644
--- a/src/guff/models/page.cr
+++ b/src/guff/models/page.cr
@@ -18,9 +18,8 @@ class Guff::Models::PageModel < Guff::Models::Model
WHERE a.site_id = ?
AND b.slug = ?
AND d.state = 'public'
- AND (0 + strftime('%s'))
- BETWEEN (0 + strftime('%s', COALESCE(b.posted_at, 'now')))
- AND (0 + strftime('%s', COALESCE(b.expires_at,'now')))
+ AND (0 + strftime('%s')) >=
+ (0 + strftime('%s', COALESCE(b.posted_at, 'now')))
",
find: "
@@ -53,9 +52,8 @@ class Guff::Models::PageModel < Guff::Models::Model
WHERE a.site_id = ?
AND b.slug = ?
AND d.state = 'public'
- AND (0 + strftime('%s'))
- BETWEEN (0 + strftime('%s', COALESCE(b.posted_at, 'now')))
- AND (0 + strftime('%s', COALESCE(b.expires_at,'now')))
+ AND (0 + strftime('%s')) >=
+ (0 + strftime('%s', COALESCE(b.posted_at, 'now')))
ORDER BY b.posted_at DESC
@@ -84,7 +82,6 @@ class Guff::Models::PageModel < Guff::Models::Model
a.site_id,
c.state,
a.posted_at,
- a.expires_at,
a.slug,
a.slug_lock,
a.name,
@@ -186,9 +183,6 @@ class Guff::Models::PageModel < Guff::Models::Model
have_posted_at : Bool = false,
posted_at : Time? = nil,
- have_expires_at : Bool = false,
- expires_at : Time? = nil,
-
slug : String? = nil,
slug_lock : Bool? = nil,
@@ -210,9 +204,6 @@ class Guff::Models::PageModel < Guff::Models::Model
have_posted_at: have_posted_at,
posted_at: posted_at,
- have_expires_at: have_expires_at,
- expires_at: expires_at,
-
slug: slug,
slug_lock: slug_lock,
diff --git a/src/guff/models/post.cr b/src/guff/models/post.cr
index 5c94d04..782cb31 100644
--- a/src/guff/models/post.cr
+++ b/src/guff/models/post.cr
@@ -60,10 +60,6 @@ class Guff::Models::PostModel < Guff::Models::Model
date(a.posted_at) AS posted_at_text,
datetime(a.posted_at) AS posted_at_text_full,
- a.expires_at,
- date(a.expires_at) AS expires_at_text,
- datetime(a.expires_at) AS expires_at_text_full,
-
a.slug,
a.slug_lock,
a.name,
@@ -141,9 +137,6 @@ class Guff::Models::PostModel < Guff::Models::Model
have_posted_at : Bool = false,
posted_at : Time? = nil,
- have_expires_at : Bool = false,
- expires_at : Time? = nil,
-
slug : String? = nil,
slug_lock : Bool? = nil,
@@ -179,15 +172,6 @@ class Guff::Models::PostModel < Guff::Models::Model
end
end
- if have_expires_at
- if expires_at
- sets << "expires_at = ?"
- args << ISO8601.format(expires_at)
- else
- sets << "expires_at = NULL"
- end
- end
-
if slug
sets << "slug = ?"
args << slug
diff --git a/src/guff/models/project.cr b/src/guff/models/project.cr
index 2aa08ae..996ce7b 100644
--- a/src/guff/models/project.cr
+++ b/src/guff/models/project.cr
@@ -18,9 +18,8 @@ class Guff::Models::ProjectModel < Guff::Models::Model
WHERE a.site_id = ?
AND b.slug = ?
AND d.state = 'public'
- AND (0 + strftime('%s'))
- BETWEEN (0 + strftime('%s', COALESCE(b.posted_at, 'now')))
- AND (0 + strftime('%s', COALESCE(b.expires_at,'now')))
+ AND (0 + strftime('%s')) >=
+ (0 + strftime('%s', COALESCE(b.posted_at, 'now')))
",
find: "
@@ -51,9 +50,8 @@ class Guff::Models::ProjectModel < Guff::Models::Model
WHERE a.site_id = ?
AND b.slug = ?
AND d.state = 'public'
- AND (0 + strftime('%s'))
- BETWEEN (0 + strftime('%s', COALESCE(b.posted_at, 'now')))
- AND (0 + strftime('%s', COALESCE(b.expires_at,'now')))
+ AND (0 + strftime('%s')) >=
+ (0 + strftime('%s', COALESCE(b.posted_at, 'now')))
ORDER BY b.created_at DESC
@@ -66,7 +64,7 @@ class Guff::Models::ProjectModel < Guff::Models::Model
set: "
UPDATE projects
- SET repo_url = ?
+ SET %s
WHERE post_id = ?
",
@@ -75,12 +73,13 @@ class Guff::Models::ProjectModel < Guff::Models::Model
a.site_id,
c.state,
a.posted_at,
- a.expires_at,
a.slug,
a.slug_lock,
a.name,
a.body,
b.repo_url,
+ b.tag_prefix,
+ b.hook_secret,
d.theme_id,
e.theme_slug
@@ -162,9 +161,6 @@ class Guff::Models::ProjectModel < Guff::Models::Model
have_posted_at : Bool = false,
posted_at : Time? = nil,
- have_expires_at : Bool = false,
- expires_at : Time? = nil,
-
slug : String? = nil,
slug_lock : Bool? = nil,
@@ -172,10 +168,15 @@ class Guff::Models::ProjectModel < Guff::Models::Model
body : String? = nil,
repo_url : String? = nil,
+ tag_prefix : String? = nil,
+ hook_secret : String? = nil,
)
db = @context.dbs.rw
db.transaction do
+ sql = [] of String
+ args = [] of String
+
@context.models.post.set(
post_id: post_id,
@@ -185,9 +186,6 @@ class Guff::Models::ProjectModel < Guff::Models::Model
have_posted_at: have_posted_at,
posted_at: posted_at,
- have_expires_at: have_expires_at,
- expires_at: expires_at,
-
slug: slug,
slug_lock: slug_lock,
@@ -195,9 +193,24 @@ class Guff::Models::ProjectModel < Guff::Models::Model
body: body,
)
- # puts "DEBUG: repo_url = #{repo_url}, post_id = #{post_id}"
if repo_url
- db.query(SQL[:set], [repo_url.to_s, post_id.to_s])
+ sql << "repo_url = ?"
+ args << repo_url.to_s
+ end
+
+ if tag_prefix
+ sql << "tag_prefix = ?"
+ args << tag_prefix.to_s
+ end
+
+ if hook_secret
+ sql << "hook_secret = ?"
+ args << hook_secret.to_s
+ end
+
+ if sql.size > 0
+ args << post_id.to_s
+ db.query(SQL[:set] % sql.join(","), args)
end
end
end