summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorAnton Davydov <antondavydov.o@gmail.com>2016-03-01 15:36:50 +0300
committerRémy Coutable <remy@rymai.me>2016-04-18 14:47:50 +0200
commit073c3d15c71a0f877b62c7d3d7417a9721da1dba (patch)
tree83dd1a990857e54ebd91f6ef3f6494e51cdd0f47 /lib/api
parent06952aaf24633550f57fd54b70d27732509935c2 (diff)
downloadgitlab-ce-073c3d15c71a0f877b62c7d3d7417a9721da1dba.tar.gz
Initial implementation if license template selector and /licenses/:key API endpoint
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/api.rb1
-rw-r--r--lib/api/licenses.rb27
2 files changed, 28 insertions, 0 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb
index 7d65145176b..cc1004f8005 100644
--- a/lib/api/api.rb
+++ b/lib/api/api.rb
@@ -57,5 +57,6 @@ module API
mount Builds
mount Variables
mount Runners
+ mount Licenses
end
end
diff --git a/lib/api/licenses.rb b/lib/api/licenses.rb
new file mode 100644
index 00000000000..7fffbef84e4
--- /dev/null
+++ b/lib/api/licenses.rb
@@ -0,0 +1,27 @@
+module API
+ # Licenses API
+ class Licenses < Grape::API
+ YEAR_TEMPLATE_REGEX = /(\[|<|{)(year|yyyy)(\]|>|})/
+ FULLNAME_TEMPLATE_REGEX = /\[fullname\]/
+
+ # Get text for specific license
+ #
+ # Parameters:
+ # key (required) - The key of a license
+ # fullname - Reository owner fullname
+ # Example Request:
+ # GET /licenses/mit
+ get 'licenses/:key', requirements: { key: /[\w.-]*/ } do
+ env['api.format'] = :txt
+ license = Licensee::License.find(params[:key]).try(:text)
+
+ if license
+ license
+ .gsub(YEAR_TEMPLATE_REGEX, Time.now.year.to_s)
+ .gsub(FULLNAME_TEMPLATE_REGEX, params[:fullname])
+ else
+ error!('License not found', 404)
+ end
+ end
+ end
+end