Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Create an Organisation on Gogs (Fly.io) via REST API #8

Closed
nelsonic opened this issue Apr 30, 2022 · 5 comments
Closed

Feat: Create an Organisation on Gogs (Fly.io) via REST API #8

nelsonic opened this issue Apr 30, 2022 · 5 comments

Comments

@nelsonic
Copy link
Member

My reading of the Org API: https://github.com/gogs/docs-api/tree/master/Organizations
is that there is no way to create an Org, e.g:

PUT /orgs/:orgname

or

POST /orgs/:orgname

So going to try and use the "Edit" endpoint:
https://github.com/gogs/docs-api/tree/master/Organizations#edit-an-organization

PATCH /orgs/:org

If that fails, I will be opening an issue on: https://github.com/gogs/docs-api/issues
And I might end up writing some Go code today. 💭

Wish me luck! 🤞

@nelsonic
Copy link
Member Author

nelsonic commented May 2, 2022

Sadly, there doesn't appear to be an org creation endpoint ...
Issue created: gogs/docs-api#33

@nelsonic nelsonic removed their assignment May 2, 2022
@nelsonic
Copy link
Member Author

nelsonic commented May 2, 2022

We are going to get around this by simply doing "org_name-repo_name in the short term. :shipit:
But it would be great to be able to programatically create organisations for GitHub Backup to work. 💭

@nelsonic
Copy link
Member Author

nelsonic commented May 2, 2022

Parking this code here for now. Sadly it doesn't work ...

  @doc """
  `patch/1` accepts `url`; 
  the `url` of the API endpoint to create the `org`.
  """
  @spec patch(String.t(), map) :: {:ok, map} | {:error, any}
  def patch(url, params) do
    body = Jason.encode!(params)
    headers = [
      {"Accept", "application/json"},
      {"Authorization", "token #{@access_token}"},
      {"Content-Type", "application/json"}
    ]
    inject_poison().patch(url, body, headers)
    |> parse_body_response()
  end

  @doc """
  `org_create/1` accepts 1 argument: `org_name` to be crated.
  """
  def org_create(org_name) do
    url = @api_base_url <> "orgs/#{org_name}?token=#{@access_token}"
    # IO.inspect(url, label: "remote_repo_delete url")
    params = %{
      full_name: org_name,
      description: org_name,
    }
    patch(url, params)
  end

@nelsonic nelsonic changed the title Create an Organisation on Gogs (Fly.io) via REST API Feat: Create an Organisation on Gogs (Fly.io) via REST API May 5, 2022
@nelsonic
Copy link
Member Author

nelsonic commented May 14, 2022

Dang ... 🤦‍♂️
Gitea allows POST /orgs to create an Org: https://try.gitea.io/api/swagger#/
image

For reference, the Gogs API docs for Organizations at the time of writing:
https://github.com/gogs/docs-api/tree/9740f402bd1e28892fe544eaac83ee016a7202df/Organizations

Were last updated Dec 17, 2018 ...
image

I didn't see this as a "Red flag" at the time because I didn't think we would need all the Org-related APIs ...
But I was wrong. Not only would the better Orgs API be useful it would be transformative in our particular use-case.

@nelsonic
Copy link
Member Author

GOTO: dwyl/gitea#7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant