Skip to content

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

Closed

Description

@nelsonic

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! 🤞

Activity

  1. self-assigned this
    on Apr 30, 2022
  2. nelsonic commented on May 2, 2022

    @nelsonic
    MemberAuthor

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

  3. removed their assignment
    on May 2, 2022
  4. nelsonic commented on May 2, 2022

    @nelsonic
    MemberAuthor

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

  5. nelsonic commented on May 2, 2022

    @nelsonic
    MemberAuthor

    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
  6. changed the title [-]Create an Organisation on Gogs (Fly.io) via REST API[/-] [+]Feat: Create an Organisation on Gogs (Fly.io) via REST API[/+] on May 5, 2022
  7. nelsonic commented on May 14, 2022

    @nelsonic
    MemberAuthor

    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.

  8. nelsonic commented on May 16, 2022

    @nelsonic
    MemberAuthor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions