Skip to content
This repository has been archived by the owner on Mar 25, 2023. It is now read-only.

Create org #8

Merged
merged 8 commits into from
May 17, 2022
Merged

Create org #8

merged 8 commits into from
May 17, 2022

Conversation

SimonLab
Copy link
Member

ref: #7

Create a new organisation on Gitea
@SimonLab SimonLab self-assigned this May 17, 2022
Add case to mock the different type of post requests
@codecov
Copy link

codecov bot commented May 17, 2022

Codecov Report

Merging #8 (d1b0f45) into main (a7ffb17) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main        #8   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            5         5           
  Lines          115       128   +13     
=========================================
+ Hits           115       128   +13     
Impacted Files Coverage Δ
lib/gitea.ex 100.00% <100.00%> (ø)
lib/http.ex 100.00% <100.00%> (ø)
lib/httpoison_mock.ex 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a7ffb17...d1b0f45. Read the comment docs.

SimonLab added 4 commits May 17, 2022 09:32
We are using mock post request to creat repos, orgs
and to convert html/markdow.
For any other endpoints the mock returns 404 status code
Add test for delete organisation
Update test to remove unused body value
@@ -40,10 +40,11 @@ defmodule Gitea.Http do
"""
@spec parse_body_response({atom, String.t()} | {:error, any}) :: {:ok, map} | {:error, any}
def parse_body_response({:error, err}), do: {:error, err}
def parse_body_response({:ok, response = %{status_code: 204}}), do: {:ok, response}
Copy link
Member Author

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

Copy link
Member

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 ...

Copy link
Member Author

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:

 if body == nil || byte_size(body) == 0 do

My first thought was to remove the byte_size(body) == 0 condition as I don't think parse_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

Copy link
Member

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. 👍

# check delete request endpooints
cond do
# match delete org
url =~ "/orgs" ->
Copy link
Member Author

Choose a reason for hiding this comment

The 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

when creating a new org we can pass a keyword list options
@SimonLab SimonLab marked this pull request as ready for review May 17, 2022 10:13
@SimonLab SimonLab assigned nelsonic and unassigned SimonLab May 17, 2022
@SimonLab SimonLab added the awaiting-review An issue or pull request that needs to be reviewed label May 17, 2022
@SimonLab SimonLab requested a review from nelsonic May 17, 2022 10:13
lib/gitea.ex Outdated
and define the description, full_name and visibility
"""
@spec remote_org_create(String.t(), list()) :: {:ok, map} | {:error, any}
def remote_org_create(org_name, opts \\ []) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason we don't just pass in a Map of params instead of the org_name and opts ? 💭

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw the remote_org_create function having only one required argument (the org_name) and the other values (description, full_name and visibility) as optional similar to the gitea api and the UI. In this case I think it makes sense to use a keyword list as it is used for this type of optional argument
see: https://elixir-lang.org/getting-started/keywords-and-maps.html#keyword-lists

Keyword lists are a data-structure used to pass options to functions

However if you consider that all the values are required we can pass a Map (or even define a struct).

Let me know if you prefer the "map" version of the function

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, sadly, remote_org_create/1 in Gogs didn't work dwyl/gogs#8 (comment) so I didn't pursue it ...
I find keyword lists cumbersome.
in this case having a single params argument with all the necessary fields (only params.username is required) will make it immediately clear to the person using the app that their params are passed in directly.

Copy link
Member

@nelsonic nelsonic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SimonLab looking good. 👍
Only one question regarding the argument for the remote_org_create/2 function:
could we not supply the params Map with the necessary fields and simplify it? 💭

@nelsonic nelsonic assigned SimonLab and unassigned nelsonic May 17, 2022
@nelsonic nelsonic added question Further information is requested in-review Issue or pull request that is currently being reviewed by the assigned person and removed awaiting-review An issue or pull request that needs to be reviewed labels May 17, 2022
@SimonLab SimonLab assigned nelsonic and unassigned SimonLab May 17, 2022
Use a Map instead of keyword list for optional API parameters
see: #8 (comment)
Copy link
Member

@nelsonic nelsonic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SimonLab looks great! Thanks for humouring me with the single params argument. 👍

p.s. in future feel free to bump the version in mix.exs so that we can easily publish the new version. 👍

@@ -40,10 +40,11 @@ defmodule Gitea.Http do
"""
@spec parse_body_response({atom, String.t()} | {:error, any}) :: {:ok, map} | {:error, any}
def parse_body_response({:error, err}), do: {:error, err}
def parse_body_response({:ok, response = %{status_code: 204}}), do: {:ok, response}
Copy link
Member

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. 👍

@nelsonic nelsonic merged commit 0562a5b into main May 17, 2022
@nelsonic nelsonic deleted the create-org-#7 branch May 17, 2022 13:35
@SimonLab SimonLab mentioned this pull request May 18, 2022
2 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
in-review Issue or pull request that is currently being reviewed by the assigned person question Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants