Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
10237d45
Commit
10237d45
authored
May 22, 2018
by
Imre Farkas
Committed by
Rémy Coutable
May 22, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose readme url in Project API
parent
4d674bd3
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
57 additions
and
6 deletions
+57
-6
app/models/project.rb
app/models/project.rb
+7
-0
changelogs/unreleased/45827-expose_readme_url_in_project_api.yml
...ogs/unreleased/45827-expose_readme_url_in_project_api.yml
+5
-0
doc/api/projects.md
doc/api/projects.md
+10
-1
lib/api/entities.rb
lib/api/entities.rb
+1
-1
spec/fixtures/api/schemas/public_api/v4/projects.json
spec/fixtures/api/schemas/public_api/v4/projects.json
+1
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+28
-0
spec/requests/api/environments_spec.rb
spec/requests/api/environments_spec.rb
+1
-1
spec/requests/api/projects_spec.rb
spec/requests/api/projects_spec.rb
+3
-2
spec/requests/api/v3/projects_spec.rb
spec/requests/api/v3/projects_spec.rb
+1
-1
No files found.
app/models/project.rb
View file @
10237d45
...
...
@@ -894,6 +894,13 @@ class Project < ActiveRecord::Base
Gitlab
::
Routing
.
url_helpers
.
project_url
(
self
)
end
def
readme_url
readme
=
repository
.
readme
if
readme
Gitlab
::
Routing
.
url_helpers
.
project_blob_url
(
self
,
File
.
join
(
default_branch
,
readme
.
path
))
end
end
def
new_issuable_address
(
author
,
address_type
)
return
unless
Gitlab
::
IncomingEmail
.
supports_issue_creation?
&&
author
...
...
changelogs/unreleased/45827-expose_readme_url_in_project_api.yml
0 → 100644
View file @
10237d45
---
title
:
Expose readme url in Project API
merge_request
:
18960
author
:
Imre Farkas
type
:
changed
doc/api/projects.md
View file @
10237d45
...
...
@@ -66,6 +66,7 @@ GET /projects
"ssh_url_to_repo"
:
"git@example.com:diaspora/diaspora-client.git"
,
"http_url_to_repo"
:
"http://example.com/diaspora/diaspora-client.git"
,
"web_url"
:
"http://example.com/diaspora/diaspora-client"
,
"readme_url"
:
"http://example.com/diaspora/diaspora-client/blob/master/README.md"
,
"tag_list"
:
[
"example"
,
"disapora client"
...
...
@@ -135,6 +136,7 @@ GET /projects
"ssh_url_to_repo"
:
"git@example.com:brightbox/puppet.git"
,
"http_url_to_repo"
:
"http://example.com/brightbox/puppet.git"
,
"web_url"
:
"http://example.com/brightbox/puppet"
,
"readme_url"
:
"http://example.com/brightbox/puppet/blob/master/README.md"
,
"tag_list"
:
[
"example"
,
"puppet"
...
...
@@ -252,6 +254,7 @@ GET /users/:user_id/projects
"ssh_url_to_repo"
:
"git@example.com:diaspora/diaspora-client.git"
,
"http_url_to_repo"
:
"http://example.com/diaspora/diaspora-client.git"
,
"web_url"
:
"http://example.com/diaspora/diaspora-client"
,
"readme_url"
:
"http://example.com/diaspora/diaspora-client/blob/master/README.md"
,
"tag_list"
:
[
"example"
,
"disapora client"
...
...
@@ -321,6 +324,7 @@ GET /users/:user_id/projects
"ssh_url_to_repo"
:
"git@example.com:brightbox/puppet.git"
,
"http_url_to_repo"
:
"http://example.com/brightbox/puppet.git"
,
"web_url"
:
"http://example.com/brightbox/puppet"
,
"readme_url"
:
"http://example.com/brightbox/puppet/blob/master/README.md"
,
"tag_list"
:
[
"example"
,
"puppet"
...
...
@@ -420,6 +424,7 @@ GET /projects/:id
"ssh_url_to_repo"
:
"git@example.com:diaspora/diaspora-project-site.git"
,
"http_url_to_repo"
:
"http://example.com/diaspora/diaspora-project-site.git"
,
"web_url"
:
"http://example.com/diaspora/diaspora-project-site"
,
"readme_url"
:
"http://example.com/diaspora/diaspora-project-site/blob/master/README.md"
,
"tag_list"
:
[
"example"
,
"disapora project"
...
...
@@ -710,6 +715,7 @@ Example responses:
"ssh_url_to_repo"
:
"git@example.com:diaspora/diaspora-project-site.git"
,
"http_url_to_repo"
:
"http://example.com/diaspora/diaspora-project-site.git"
,
"web_url"
:
"http://example.com/diaspora/diaspora-project-site"
,
"readme_url"
:
"http://example.com/diaspora/diaspora-project-site/blob/master/README.md"
,
"tag_list"
:
[
"example"
,
"disapora project"
...
...
@@ -788,6 +794,7 @@ Example response:
"ssh_url_to_repo"
:
"git@example.com:diaspora/diaspora-project-site.git"
,
"http_url_to_repo"
:
"http://example.com/diaspora/diaspora-project-site.git"
,
"web_url"
:
"http://example.com/diaspora/diaspora-project-site"
,
"readme_url"
:
"http://example.com/diaspora/diaspora-project-site/blob/master/README.md"
,
"tag_list"
:
[
"example"
,
"disapora project"
...
...
@@ -865,6 +872,7 @@ Example response:
"ssh_url_to_repo"
:
"git@example.com:diaspora/diaspora-project-site.git"
,
"http_url_to_repo"
:
"http://example.com/diaspora/diaspora-project-site.git"
,
"web_url"
:
"http://example.com/diaspora/diaspora-project-site"
,
"readme_url"
:
"http://example.com/diaspora/diaspora-project-site/blob/master/README.md"
,
"tag_list"
:
[
"example"
,
"disapora project"
...
...
@@ -966,6 +974,7 @@ Example response:
"ssh_url_to_repo"
:
"git@example.com:diaspora/diaspora-project-site.git"
,
"http_url_to_repo"
:
"http://example.com/diaspora/diaspora-project-site.git"
,
"web_url"
:
"http://example.com/diaspora/diaspora-project-site"
,
"readme_url"
:
"http://example.com/diaspora/diaspora-project-site/blob/master/README.md"
,
"tag_list"
:
[
"example"
,
"disapora project"
...
...
@@ -1061,6 +1070,7 @@ Example response:
"ssh_url_to_repo"
:
"git@example.com:diaspora/diaspora-project-site.git"
,
"http_url_to_repo"
:
"http://example.com/diaspora/diaspora-project-site.git"
,
"web_url"
:
"http://example.com/diaspora/diaspora-project-site"
,
"readme_url"
:
"http://example.com/diaspora/diaspora-project-site/blob/master/README.md"
,
"tag_list"
:
[
"example"
,
"disapora project"
...
...
@@ -1421,4 +1431,3 @@ GET /projects/:id/snapshot
| --------- | ---- | -------- | ----------- |
|
`id`
| integer/string | yes | The ID or
[
URL-encoded path of the project
](
README.md#namespaced-path-encoding
)
|
|
`wiki`
| boolean | no | Whether to download the wiki, rather than project, repository |
lib/api/entities.rb
View file @
10237d45
...
...
@@ -125,7 +125,7 @@ module API
# (fixed in https://github.com/rails/rails/pull/25976).
project
.
tags
.
map
(
&
:name
).
sort
end
expose
:ssh_url_to_repo
,
:http_url_to_repo
,
:web_url
expose
:ssh_url_to_repo
,
:http_url_to_repo
,
:web_url
,
:readme_url
expose
:avatar_url
do
|
project
,
options
|
project
.
avatar_url
(
only_path:
false
)
end
...
...
spec/fixtures/api/schemas/public_api/v4/projects.json
View file @
10237d45
...
...
@@ -20,6 +20,7 @@
"ssh_url_to_repo"
:
{
"type"
:
"string"
},
"http_url_to_repo"
:
{
"type"
:
"string"
},
"web_url"
:
{
"type"
:
"string"
},
"readme_url"
:
{
"type"
:
[
"string"
,
"null"
]
},
"avatar_url"
:
{
"type"
:
[
"string"
,
"null"
]
},
"star_count"
:
{
"type"
:
"integer"
},
"forks_count"
:
{
"type"
:
"integer"
},
...
...
spec/models/project_spec.rb
View file @
10237d45
...
...
@@ -469,6 +469,34 @@ describe Project do
end
end
describe
"#readme_url"
do
let
(
:project
)
{
create
(
:project
,
:repository
,
path:
"somewhere"
)
}
context
'with a non-existing repository'
do
it
'returns nil'
do
allow
(
project
.
repository
).
to
receive
(
:tree
).
with
(
:head
).
and_return
(
nil
)
expect
(
project
.
readme_url
).
to
be_nil
end
end
context
'with an existing repository'
do
context
'when no README exists'
do
it
'returns nil'
do
allow_any_instance_of
(
Tree
).
to
receive
(
:readme
).
and_return
(
nil
)
expect
(
project
.
readme_url
).
to
be_nil
end
end
context
'when a README exists'
do
it
'returns the README'
do
expect
(
project
.
readme_url
).
to
eql
(
"
#{
Gitlab
.
config
.
gitlab
.
url
}
/
#{
project
.
namespace
.
full_path
}
/somewhere/blob/master/README.md"
)
end
end
end
end
describe
"#new_issuable_address"
do
let
(
:project
)
{
create
(
:project
,
path:
"somewhere"
)
}
let
(
:user
)
{
create
(
:user
)
}
...
...
spec/requests/api/environments_spec.rb
View file @
10237d45
...
...
@@ -15,7 +15,7 @@ describe API::Environments do
it
'returns project environments'
do
project_data_keys
=
%w(
id description default_branch tag_list
ssh_url_to_repo http_url_to_repo web_url
ssh_url_to_repo http_url_to_repo web_url
readme_url
name name_with_namespace
path path_with_namespace
star_count forks_count
...
...
spec/requests/api/projects_spec.rb
View file @
10237d45
...
...
@@ -18,7 +18,7 @@ describe API::Projects do
let
(
:user2
)
{
create
(
:user
)
}
let
(
:user3
)
{
create
(
:user
)
}
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:project
)
{
create
(
:project
,
namespace:
user
.
namespace
)
}
let
(
:project
)
{
create
(
:project
,
:repository
,
namespace:
user
.
namespace
)
}
let
(
:project2
)
{
create
(
:project
,
namespace:
user
.
namespace
)
}
let
(
:snippet
)
{
create
(
:project_snippet
,
:public
,
author:
user
,
project:
project
,
title:
'example'
)
}
let
(
:project_member
)
{
create
(
:project_member
,
:developer
,
user:
user3
,
project:
project
)
}
...
...
@@ -220,7 +220,7 @@ describe API::Projects do
it
'returns a simplified version of all the projects'
do
expected_keys
=
%w(
id description default_branch tag_list
ssh_url_to_repo http_url_to_repo web_url
ssh_url_to_repo http_url_to_repo web_url
readme_url
name name_with_namespace
path path_with_namespace
star_count forks_count
...
...
@@ -854,6 +854,7 @@ describe API::Projects do
expect
(
json_response
[
'only_allow_merge_if_pipeline_succeeds'
]).
to
eq
(
project
.
only_allow_merge_if_pipeline_succeeds
)
expect
(
json_response
[
'only_allow_merge_if_all_discussions_are_resolved'
]).
to
eq
(
project
.
only_allow_merge_if_all_discussions_are_resolved
)
expect
(
json_response
[
'merge_method'
]).
to
eq
(
project
.
merge_method
.
to_s
)
expect
(
json_response
[
'readme_url'
]).
to
eq
(
project
.
readme_url
)
end
it
'returns a project by path name'
do
...
...
spec/requests/api/v3/projects_spec.rb
View file @
10237d45
...
...
@@ -82,7 +82,7 @@ describe API::V3::Projects do
it
'returns a simplified version of all the projects'
do
expected_keys
=
%w(
id description default_branch tag_list
ssh_url_to_repo http_url_to_repo web_url
ssh_url_to_repo http_url_to_repo web_url
readme_url
name name_with_namespace
path path_with_namespace
star_count forks_count
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment