Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into master-mipmip
Browse files Browse the repository at this point in the history
  • Loading branch information
mipmip committed Dec 21, 2020
2 parents 65f38fe + 9934f9f commit ae64db5
Show file tree
Hide file tree
Showing 11 changed files with 282 additions and 50 deletions.
34 changes: 19 additions & 15 deletions .circleci/config.yml
Expand Up @@ -23,21 +23,25 @@ jobs:
- run:
name: "Build API documents"
command: |
COMMIT_HASH=$(git rev-parse --short HEAD)
COMMIT_DATE=$(git log -1 --format=%ci)
COMMIT_STATUS="[${COMMIT_HASH}](https://${GH_REF}/commit/${COMMIT_HASH})"
sed -i -e "s/latest commit/$(echo ${COMMIT_STATUS} | sed -e "s/\//\\\\\//g") (${COMMIT_DATE})/" README.md
crystal doc
if [[ "${CIRCLE_BRANCH}" == "master" ]] && [[ ! "${CIRCLE_PR_NUMBER}" ]]; then
COMMIT_HASH=$(git rev-parse --short HEAD)
COMMIT_DATE=$(git log -1 --format=%ci)
COMMIT_STATUS="[${COMMIT_HASH}](https://${GH_REF}/commit/${COMMIT_HASH})"
sed -i -e "s/latest commit/$(echo ${COMMIT_STATUS} | sed -e "s/\//\\\\\//g") (${COMMIT_DATE})/" README.md
crystal doc
fi
- deploy:
name: "Upload to gh-page"
command: |
git config --global user.name "$GIT_USER"
git config --global user.email "$GIT_EMAIL"
cd ${DOCS_PATH}
git init
git remote add origin $GIT_REPO
git fetch origin
git reset origin/gh-pages
git add -A .
git commit --allow-empty -m "Updating documents via ${COMMIT_HASH}"
git push origin HEAD:gh-pages
if [[ "${CIRCLE_BRANCH}" == "master" ]] && [[ ! "${CIRCLE_PR_NUMBER}" ]]; then
git config --global user.name "$GIT_USER"
git config --global user.email "$GIT_EMAIL"
cd ${DOCS_PATH}
git init
git remote add origin $GIT_REPO
git fetch origin
git reset origin/gh-pages
git add -A .
git commit --allow-empty -m "Updating documents via ${COMMIT_HASH}"
git push origin HEAD:gh-pages
fi
19 changes: 18 additions & 1 deletion CHANGELOG.md
Expand Up @@ -9,6 +9,22 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

> TODO
## [0.6.0] (2020-12-21)

### Added

- Add custom attributes for users, projects and groups [#32](https://github.com/icyleaf/gitlab.cr/issues/32) [#37](https://github.com/icyleaf/gitlab.cr/issues/37) (thanks @[mipmip](https://github.com/mipmip))
- Add authenticating with a key by figerprint [#36](https://github.com/icyleaf/gitlab.cr/issues/36) (thanks @[mipmip](https://github.com/mipmip))
- Add poroject pages domain [#31](https://github.com/icyleaf/gitlab.cr/issues/31) (thanks @[mipmip](https://github.com/mipmip))

### Changed

- Change delete behaviour since Gitlab 9.0 [#33](https://github.com/icyleaf/gitlab.cr/issues/33) (thanks @[mipmip](https://github.com/mipmip))

### Fixed

- Compatibility with Crystal 0.30, Test passed 0.31

## [0.5.0] (2019-05-20)

### Fixed
Expand Down Expand Up @@ -113,7 +129,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- [initial implementation](https://github.com/icyleaf/gitlab.cr/issues?q=milestone%3A0.2.0+is%3Aclosed)

[Unreleased]: https://github.com/icyleaf/gitlab.cr/compare/v0.5.0...HEAD
[Unreleased]: https://github.com/icyleaf/gitlab.cr/compare/v0.6.0...HEAD
[0.6.0]: https://github.com/icyleaf/gitlab.cr/compare/v0.5.0...v0.6.0
[0.5.0]: https://github.com/icyleaf/gitlab.cr/compare/v0.4.0...v0.5.0
[0.4.0]: https://github.com/icyleaf/gitlab.cr/compare/v0.3.5...v0.4.0
[0.3.5]: https://github.com/icyleaf/gitlab.cr/compare/v0.3.4...v0.3.5
Expand Down
2 changes: 1 addition & 1 deletion shard.yml
@@ -1,5 +1,5 @@
name: gitlab
version: 0.5.0
version: 0.6.0

dependencies:
halite:
Expand Down
60 changes: 57 additions & 3 deletions spec/gitlab/client/project_spec.cr
Expand Up @@ -77,8 +77,10 @@ describe Gitlab::Client::Project do
stub_delete("/projects/Gitlab", "project")
project = client.delete_project("Gitlab")

project["name"].as_s.should eq "Gitlab"
project["owner"]["name"].as_s.should eq "John Smith"
project.should be_a JSON::Any

project.as(JSON::Any)["name"].as_s.should eq "Gitlab"
project.as(JSON::Any)["owner"]["name"].as_s.should eq "John Smith"
end
end

Expand Down Expand Up @@ -150,7 +152,59 @@ describe Gitlab::Client::Project do
stub_delete("/projects/3/members/1", "team_member")
team_member = client.remove_project_member(3, 1)

team_member["name"].as_s.should eq "John Smith"
team_member.as(JSON::Any)["name"].as_s.should eq "John Smith"
end
end

describe ".pages_domains" do
it "should return a paginated response of pages domains" do
stub_get("/projects/58/pages/domains", "pages_domains")
pages_domains = client.project_pages_domains(58)

pages_domains.should be_a JSON::Any
pages_domains[0]["domain"].as_s.should eq "example-pages-domain.com"
end
end

describe ".pages_domain" do
it "should return information about a pages domain" do
stub_get("/projects/58/pages/domains/example-pages-domain.com", "pages_domain")
pages_domain = client.project_pages_domain(58, "example-pages-domain.com")

pages_domain["domain"].as_s.should eq "example-pages-domain.com"
end
end

describe ".add_pages_domain" do
it "should return information about an added pages domain" do
stub_post("/projects/58/pages/domains", "pages_domain")
pages_domain = client.add_project_pages_domain(58, "example-pages-domain.com")

pages_domain["domain"].as_s.should eq "example-pages-domain.com"
end
end

describe ".edit_pages_domain" do
it "should return information about an edited pages domain" do
form = {
"domain" => "example-pages-domain.com",
"auto_ssl_enabled" => true
}
stub_put("/projects/58/pages/domains", "pages_domain", form: form)
pages_domain = client.edit_project_pages_domain(58, "example-pages-domain.com", form)
# I DON'T UNDERSTAND WHY THIS FAILS
#pages_domain = client.edit_project_pages_domain(58, "example-pages-domain.com", {"auto_ssl_enabled"=>true})

pages_domain["domain"].as_s.should eq "example-pages-domain.com"
end
end

describe ".remove_pages_domain" do
it "should return information about a removed pages domain" do
stub_delete("/projects/58/pages/domains/example-pages-domain.com", "pages_domain")
pages_domain = client.remove_project_pages_domain(58, "example-pages-domain.com")

pages_domain.as(JSON::Any)["domain"].as_s.should eq "example-pages-domain.com"
end
end

Expand Down
9 changes: 8 additions & 1 deletion spec/gitlab/client/tag_spec.cr
Expand Up @@ -54,7 +54,14 @@ describe Gitlab::Client::Tag do
stub_delete("/projects/3/repository/tag/v1.0.0", "project_tag_lightweight")
tag = client.delete_tag(3, "v1.0.0")

tag["name"].as_s.should eq "v1.0.0"
tag.should be_a JSON::Any
tag.as(JSON::Any)["name"].as_s.should eq "v1.0.0"
end

it "should return boolean since 9.0" do
stub_delete("/projects/4/repository/tag/v1.0.0")
result = client.delete_tag(4, "v1.0.0")
result.should be_true
end
end

Expand Down
58 changes: 53 additions & 5 deletions spec/gitlab/client/user_spec.cr
Expand Up @@ -22,7 +22,7 @@ describe Gitlab::Client::User do
end
end

context "withount user ID passed" do
context "without user ID passed" do
it "should return a json data of user" do
stub_get("/user", "user")
user = client.user
Expand Down Expand Up @@ -70,7 +70,15 @@ describe Gitlab::Client::User do
stub_delete("/users/1", "user")

user = client.delete_user(1)
user["email"].as_s.should eq "john@example.com"
user.should be_a JSON::Any
user.as(JSON::Any)["email"].as_s.should eq "john@example.com"
end

it "should return true about a deleted user since Gitlab 9.0" do
stub_delete("/users/2")

r = client.delete_user(2)
r.should be_true
end
end

Expand Down Expand Up @@ -106,10 +114,10 @@ describe Gitlab::Client::User do

describe ".delete_custom_attribute" do
it "should return boolean" do
stub_delete("/users/1/custom_attributes/custom_key","user_delete_custom_attribute")
stub_delete("/users/1/custom_attributes/custom_key")

result = client.user_delete_custom_attribute(1, "custom_key")
result.size.should eq 0
result.should be_true
end
end

Expand Down Expand Up @@ -158,7 +166,30 @@ describe Gitlab::Client::User do
stub_delete("/user/keys/1", "key")
key = client.delete_ssh_key(1)

key["title"].as_s.should eq "narkoz@helium"
key.should be_a JSON::Any
key.as(JSON::Any)["title"].as_s.should eq "narkoz@helium"

end

it "should return boolean since 9.0" do
stub_delete("/user/keys/2")
key = client.delete_ssh_key(2)
key.should be_true
end

it "should return information about a deleted SSH key" do
stub_delete("/users/1/keys/1", "key")
key = client.delete_ssh_key(1,1)

key.should be_a JSON::Any
key.as(JSON::Any)["title"].as_s.should eq "narkoz@helium"

end

it "should return boolean since 9.0" do
stub_delete("/users/2/keys/2")
key = client.delete_ssh_key(2,2)
key.should be_true
end
end

Expand Down Expand Up @@ -224,6 +255,23 @@ describe Gitlab::Client::User do
email.should be_truthy
end
end

describe "without user ID" do
it "should return boolean since 9.0" do
stub_delete("/user/emails/3")
email = client.delete_email(3)
email.should be_true
end
end

describe "with user ID" do
it "should return boolean since 9.0" do
stub_delete("/users/4/emails/5")
email = client.delete_email(5, 4)
email.should be_true
end
end

end

describe ".user_search" do
Expand Down
16 changes: 11 additions & 5 deletions spec/spec_helper.cr
Expand Up @@ -46,11 +46,17 @@ def stub_put(path, fixture, form = nil, response_headers = {} of String => Strin
end

# DELETE
def stub_delete(path, fixture, form = nil, response_headers = {} of String => String)
def stub_delete(path, fixture = nil, form = nil, response_headers = {} of String => String, status = 200)
body = HTTP::Params.encode(form) if form

response_headers.merge!({"Content-Type" => "application/json"})
WebMock.stub(:delete, "#{client.endpoint}#{path}")
.with(body: body, headers: {"Private-Token" => client.token})
.to_return(body: load_fixture(fixture), headers: response_headers)
if fixture
response_headers.merge!({"Content-Type" => "application/json"})
WebMock.stub(:delete, "#{client.endpoint}#{path}")
.with(body: body, headers: {"Private-Token" => client.token})
.to_return(body: load_fixture(fixture), status: status, headers: response_headers)
else
WebMock.stub(:delete, "#{client.endpoint}#{path}")
.with(body: body, headers: {"Private-Token" => client.token})
.to_return(status: 204)
end
end
2 changes: 1 addition & 1 deletion src/gitlab.cr
@@ -1,7 +1,7 @@
require "./gitlab/**"

module Gitlab
VERSION = "0.5.0"
VERSION = "0.6.0"

# Alias for Gitlab::Client.new
def self.client(endpoint : String, token : String) : Client
Expand Down
87 changes: 83 additions & 4 deletions src/gitlab/client/project.cr
Expand Up @@ -279,8 +279,10 @@ module Gitlab
# ```
# client.delete_project(42)
# ```
def delete_project(project : Int32 | String) : JSON::Any
delete("projects/#{project}").parse
def delete_project(project : Int32 | String) : JSON::Any | Bool
response = delete("projects/#{project}")
return true if response.status_code == 204
response.parse
end

# Get a list of a project's team members.
Expand Down Expand Up @@ -355,8 +357,85 @@ module Gitlab
# ```
# client.remove_project_member('gitlab', 2)
# ```
def remove_project_member(project : Int32 | String, user_id : Int32) : JSON::Any
delete("projects/#{project}/members/#{user_id}").parse
def remove_project_member(project : Int32 | String, user_id : Int32) : JSON::Any | Bool
response = delete("projects/#{project}/members/#{user_id}")
return true if response.status_code == 204
response.parse
end

# Get a list of a project's pages domains.
#
# - param [Int32, String] project The ID or name of a project. If using namespaced projects call make sure that the NAMESPACE/PROJECT_NAME is URL-encoded.
# - return [JSON::Any] List of pages domains under a project.
#
# ```
# client.project_pages_domains(42)
# client.project_pages_domains('gitlab')
# ```
def project_pages_domains(project : Int32 | String) : JSON::Any
get("projects/#{project}/pages/domains").parse
end

# Gets a project pages domain.
#
# - param [Int32, String] project The ID or name of a project. If using namespaced projects call make sure that the NAMESPACE/PROJECT_NAME is URL-encoded. If using namespaced projects call make sure that the NAMESPACE/PROJECT_NAME is URL-encoded.
# - param [String] The custom domain.
# - return [JSON::Any] Information about pages domain under a project.
#
# ```
# client.project_pages_domain(1, "pages-domain.com")
# ```
def project_pages_domain(project : Int32 | String, domain : String) : JSON::Any
get("projects/#{project}/pages/domains/#{domain}").parse
end

# Adds a pages domain to project.
#
# - param [Int32, String] project_id The ID or name of a project.
# - param [String] domain The custom domain.
# - params [Hash] form A customizable set of options.
# - option form [Bool] :auto_ssl_enabled Enables automatic generation of SSL certificates issued by Let’s Encrypt for custom domains.
# - option form [String] :certificate The certificate in PEM format with intermediates following in most specific to least specific order.
# - option form [String] :key The certificate key in PEM format.
# - return [JSON::Any] Information about added pages domain.
#
# ```
# client.add_project_pages_domain('gitlab', "pages-domain.com", {"auto_ssl_enabled" => true})
# ```
def add_project_pages_domain(project : Int32 | String, domain : String, form : Hash = {} of String => String) : JSON::Any
post("projects/#{project}/pages/domains", form: form.merge({ "domain" => domain })).parse
end

# Updates a pages domain project.
#
# - param [Int32, String] project_id The ID or name of a project.
# - param [String] domain The custom domain.
# - params [Hash] form A customizable set of options.
# - option form [Bool] :auto_ssl_enabled Enables automatic generation of SSL certificates issued by Let’s Encrypt for custom domains.
# - option form [String] :certificate The certificate in PEM format with intermediates following in most specific to least specific order.
# - option form [String] :key The certificate key in PEM format.
# - return [JSON::Any] Information about added pages domain.
#
# ```
# client.edit_project_pages_domain('gitlab', "pages-domain.com", {"auto_ssl_enabled" => true})
# ```
def edit_project_pages_domain(project : Int32 | String, domain : String, form : Hash = {} of String => String) : JSON::Any
put("projects/#{project}/pages/domains", form: form.merge({ "domain" => domain })).parse
end

# Removes a pages domain from project.
#
# - param [Int32, String] project The ID or name of a project. If using namespaced projects call make sure that the NAMESPACE/PROJECT_NAME is URL-encoded.
# - param [String] domain The custom domain.
# - return [JSON::Any] Information about removed team member.
#
# ```
# client.remove_project_pages_domain(1, "pages-domain.com")
# ```
def remove_project_pages_domain(project : Int32 | String, domain : String) : JSON::Any | Bool
response = delete("projects/#{project}/pages/domains/#{domain}")
return true if response.status_code == 204
response.parse
end

# Get a list of a project's pages domains.
Expand Down

0 comments on commit ae64db5

Please sign in to comment.