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

Transfer ownsership via json api #5075

Closed
jaroel opened this issue Oct 12, 2018 · 6 comments
Closed

Transfer ownsership via json api #5075

jaroel opened this issue Oct 12, 2018 · 6 comments
Labels
issue/stale modifies/api This PR adds API routes or modifies them type/feature Completely new functionality. Can only be merged if feature freeze is not active.

Comments

@jaroel
Copy link

jaroel commented Oct 12, 2018

Hi,

There's not an option to transfer ownership of a repo using the json API.
I'd like to move project to an "archive" organisation when the project is done.

@lunny lunny added type/feature Completely new functionality. Can only be merged if feature freeze is not active. modifies/api This PR adds API routes or modifies them labels Oct 12, 2018
@jaroel
Copy link
Author

jaroel commented Oct 13, 2018

Here's a workaround:

import requests
from lxml import html

LOGIN_URL = "https://git.mydomain.com/user/login"
REPO_SETTINGS_URL = "https://git.mydomain.com/{org}/{repo}/settings"
USERNAME = "admin"
PASSWORD = "password"


def get_csrf(resp):
    # Get the csrf token from the html
    doc = html.fromstring(resp.content)
    return doc.find('*//input[@name="_csrf"]').value


def transfer_ownsership(reponame, source_org, target_org):
    session = requests.Session()

    # Authenticate
    resp = session.get(LOGIN_URL)
    session.post(
        LOGIN_URL,
        data={
            "_csrf": get_csrf(resp),
            "user_name": USERNAME,
            "password": PASSWORD,
        },
    )

    # Transfer to other org
    repo_settings_url = REPO_SETTINGS_URL.format(org=source_org, repo=reponame)
    resp = session.get(repo_settings_url)
    session.post(
        repo_settings_url,
        data={
            "_csrf": get_csrf(resp),
            "action": "transfer",
            "repo_name": reponame,
            "new_owner_name": target_org,
        },
    )


# Transfer myproject from SOURCE_ORG to TARGET_ORG
transfer_ownsership('myproject', 'projects', 'archived_projects')

@stale
Copy link

stale bot commented Jan 6, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.

@stale stale bot added the issue/stale label Jan 6, 2019
@stale
Copy link

stale bot commented Feb 22, 2019

This issue has been automatically closed because of inactivity. You can re-open it if needed.

@stale stale bot closed this as completed Feb 22, 2019
@hrvoj3e
Copy link

hrvoj3e commented Feb 26, 2020

Will this be supported in the future?

Usecase:

  • developer starts a project under his username
  • project grows and must be added to an organisation
  • other devs are added to the team

Are there any other ways to cover my usecase?
Forks maybe? Hm...

@jolheiser
Copy link
Member

This was implemented in #9947

@hrvoj3e
Copy link

hrvoj3e commented Feb 26, 2020

Wow. Nice. 👍

@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue/stale modifies/api This PR adds API routes or modifies them type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

No branches or pull requests

4 participants