summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Schilling <rschilling@student.tugraz.at>2016-10-12 13:32:48 +0200
committerRobert Schilling <rschilling@student.tugraz.at>2016-10-12 16:47:35 +0200
commitb998479c81512b7c9a2cff28e7aabff3c4be0424 (patch)
treebb6ad3e585b1096f804dc354eebabb68bf93b9ec
parent7c07c07d7a2b93ab81964b9cd28736652da1370a (diff)
downloadgitlab-ce-api-version.tar.gz
API: Version informationapi-version
-rw-r--r--CHANGELOG1
-rw-r--r--doc/api/README.md1
-rw-r--r--doc/api/version.md23
-rw-r--r--lib/api/api.rb1
-rw-r--r--lib/api/version.rb12
-rw-r--r--spec/requests/api/version_spec.rb27
6 files changed, 65 insertions, 0 deletions
diff --git a/CHANGELOG b/CHANGELOG
index e478e8c3365..401d0d66de3 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -30,6 +30,7 @@ v 8.13.0 (unreleased)
- Cache rendered markdown in the database, rather than Redis
- Avoid database queries on Banzai::ReferenceParser::BaseParser for nodes without references
- Simplify Mentionable concern instance methods
+ - API: Ability to retrieve version information (Robert Schilling)
- Fix permission for setting an issue's due date
- API: Multi-file commit !6096 (mahcsig)
- Revert "Label list shows all issues (opened or closed) with that label"
diff --git a/doc/api/README.md b/doc/api/README.md
index 9e907689c80..75b098f2eeb 100644
--- a/doc/api/README.md
+++ b/doc/api/README.md
@@ -46,6 +46,7 @@ following locations:
- [Todos](todos.md)
- [Users](users.md)
- [Validate CI configuration](ci/lint.md)
+- [Version](version.md)
### Internal CI API
diff --git a/doc/api/version.md b/doc/api/version.md
new file mode 100644
index 00000000000..287d17cf97f
--- /dev/null
+++ b/doc/api/version.md
@@ -0,0 +1,23 @@
+# Version API
+
+>**Note:** This feature was introduced in GitLab 8.13
+
+Retrieve version information for this GitLab instance. Responds `200 OK` for
+authenticated users.
+
+```
+GET /version
+```
+
+```bash
+curl --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/version
+```
+
+Example response:
+
+```json
+{
+ "version": "8.13.0-pre",
+ "revision": "4e963fe"
+}
+```
diff --git a/lib/api/api.rb b/lib/api/api.rb
index 99722a0a65c..eb4e1fc504f 100644
--- a/lib/api/api.rb
+++ b/lib/api/api.rb
@@ -73,6 +73,7 @@ module API
mount ::API::Triggers
mount ::API::Users
mount ::API::Variables
+ mount ::API::Version
route :any, '*path' do
error!('404 Not Found', 404)
diff --git a/lib/api/version.rb b/lib/api/version.rb
new file mode 100644
index 00000000000..9ba576bd828
--- /dev/null
+++ b/lib/api/version.rb
@@ -0,0 +1,12 @@
+module API
+ class Version < Grape::API
+ before { authenticate! }
+
+ desc 'Get the version information of the GitLab instance.' do
+ detail 'This feature was introduced in GitLab 8.13.'
+ end
+ get '/version' do
+ { version: Gitlab::VERSION, revision: Gitlab::REVISION }
+ end
+ end
+end
diff --git a/spec/requests/api/version_spec.rb b/spec/requests/api/version_spec.rb
new file mode 100644
index 00000000000..54b69a0cae7
--- /dev/null
+++ b/spec/requests/api/version_spec.rb
@@ -0,0 +1,27 @@
+require 'spec_helper'
+
+describe API::API, api: true do
+ include ApiHelpers
+
+ describe 'GET /version' do
+ context 'when unauthenticated' do
+ it 'returns authentication error' do
+ get api('/version')
+
+ expect(response).to have_http_status(401)
+ end
+ end
+
+ context 'when authenticated' do
+ let(:user) { create(:user) }
+
+ it 'returns the version information' do
+ get api('/version', user)
+
+ expect(response).to have_http_status(200)
+ expect(json_response['version']).to eq(Gitlab::VERSION)
+ expect(json_response['revision']).to eq(Gitlab::REVISION)
+ end
+ end
+ end
+end