This repository has been archived by the owner on Mar 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Create org #8
Merged
Merged
Create org #8
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cca97b6
Create organistaion
SimonLab 0c63210
Fix test for mockhttp with post request
SimonLab 0003931
Add test for post request mock
SimonLab ce47c90
Update http mock for delete org
SimonLab 7cd5d91
Merge branch 'main' into create-org-#7
SimonLab fee4d1c
Update test
SimonLab 572c6dc
Test create org with options
SimonLab d1b0f45
Update remote_org_create parameters
SimonLab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,16 +102,24 @@ defmodule Gitea.HTTPoisonMock do | |
def post(url, body, headers) do | ||
Logger.debug("Gitea.HTTPoisonMock.post/3 #{url}") | ||
|
||
if String.contains?(url, "markdown/raw") do | ||
post_raw_html(url, body, headers) | ||
else | ||
body_map = Jason.decode!(body) |> Useful.atomize_map_keys() | ||
cond do | ||
url =~ "markdown/raw" -> | ||
post_raw_html(url, body, headers) | ||
|
||
response_body = | ||
make_repo_create_post_response_body(body_map.name) | ||
|> Jason.encode!() | ||
url =~ "/repo" -> | ||
body_map = Jason.decode!(body) |> Useful.atomize_map_keys() | ||
|
||
{:ok, %HTTPoison.Response{body: response_body, status_code: 200}} | ||
response_body = | ||
make_repo_create_post_response_body(body_map.name) | ||
|> Jason.encode!() | ||
|
||
{:ok, %HTTPoison.Response{body: response_body, status_code: 200}} | ||
|
||
url =~ "/orgs" -> | ||
{:ok, %HTTPoison.Response{body: Jason.encode!(%{username: "new_org"}), status_code: 200}} | ||
|
||
true -> | ||
{:ok, %HTTPoison.Response{body: Jason.encode!(""), status_code: 404}} | ||
end | ||
end | ||
|
||
|
@@ -135,11 +143,22 @@ defmodule Gitea.HTTPoisonMock do | |
""" | ||
def delete(url) do | ||
Logger.debug("Gitea.HTTPoisonMock.delete/1 #{url}") | ||
# check delete request endpooints | ||
cond do | ||
# match delete org | ||
url =~ "/orgs" -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check what is the delete request (delete org or delete repo at the moment) and returns response accordingly |
||
{:ok, | ||
%HTTPoison.Response{ | ||
body: "", | ||
status_code: 204 | ||
}} | ||
|
||
{:ok, | ||
%HTTPoison.Response{ | ||
body: Jason.encode!(%{deleted: List.first(String.split(url, "?"))}), | ||
status_code: 200 | ||
}} | ||
true -> | ||
{:ok, | ||
%HTTPoison.Response{ | ||
body: Jason.encode!(%{deleted: List.first(String.split(url, "?"))}), | ||
status_code: 200 | ||
}} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check for status code here instead of checking if the body exists as a 204 status code response has an empty body.
see https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/204 and https://gitea-server.fly.dev/api/swagger#/organization/orgDelete
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth including this comment in-line (in the code) as it will be lost here in the PR ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I've added this definition is to avoid changing the code below:
My first thought was to remove the
byte_size(body) == 0
condition as I don't thinkparse_body_response
should return{:error, :no_body}
when the body is an empty string (it is defined like this when deleting orgs or repos). However I didn't want to break existing tests in case I missed something.I'll add a comment in the code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I didn't know what to return. Please use your judgement. 👍