Giter VIP home page Giter VIP logo

Comments (3)

jbweston avatar jbweston commented on August 11, 2024

You can use Github OAuth to sign in to the Gitlab instance

from adaptive.

basnijholt avatar basnijholt commented on August 11, 2024

We have moved the development to GitHub as of today!

from adaptive.

basnijholt avatar basnijholt commented on August 11, 2024

We used the following script:

import re
import gitlab
import github

gitlab_url = 'https://gitlab.kwant-project.org/'
repo_name_gl = 'qt/adaptive'
repo_name_gh = "python-adaptive/adaptive"

# gh = github.Github("...") # Joe
gh = github.Github("...") # Bas

gl = gitlab.Gitlab(gitlab_url, private_token=...', api_version=4)
gl.auth()

repo_gl = gl.projects.get(repo_name_gl)
mrs = repo_gl.mergerequests.list(state='opened')
issues = repo_gl.issues.list(all=True)

repo_gh = gh.get_repo(repo_name_gh)

def random_color():
    import random
    r = lambda: random.randint(0, 255)
    return '%02X%02X%02X' % (r(),r(),r())

def get_label(label):
    try:
        return repo_gh.create_label(label, color=random_color())
    except:
        return repo_gh.get_label(label)

def get_issue_body(issue, is_pr=False):
    attrs = issue.attributes
    author = attrs["author"]
    username_url = get_username_url(author["username"])
    url = attrs["web_url"]
    output = (f'## ([original {"merge request" if is_pr else "issue"} on GitLab]({url}))'
            '\n\n'
            f'_opened by {author["name"]} ({username_url}) at {attrs["created_at"]}_'
            '\n\n'
            f'{attrs["description"]}'
           )
    return parse(output)

def get_comment_body(discussion, url):
    attrs = discussion.attributes
    note = attrs['notes'][0]
    body = note['body']
    author = note['author']
    username_url = get_username_url(author["username"])
    output = (
        f'_originally posted by {author["name"]} ({username_url}) at {note["created_at"]} on [GitLab]({url})_'
        '\n\n'
        f'{body}'
       )
    return parse(output)

def human_posted(discussion):
    return not discussion.attributes['notes'][0]['system']

def get_username_url(username):
    url = gitlab_url + username
    return f'[@{username}]({url})'

def parse(text):
    repo_url = gitlab_url + repo_name_gl
    text = re.sub('!(\d{1,3})', rf'[gitlab:!\1]({repo_url}/merge_requests/\1)', text)
    text = re.sub('#(\d{1,3})', rf'[gitlab:#\1]({repo_url}/issues/\1)', text)
    return text

import time

for issue in issues:
    time.sleep(2)
    attrs = issue.attributes
    labels = [get_label(label) for label in attrs["labels"]]
    new_issue = repo_gh.create_issue(title=attrs['title'], body=get_issue_body(issue), labels=labels)
    for discussion in issue.discussions.list():
        if human_posted(discussion):
            time.sleep(0.5)
            comment_body = get_comment_body(discussion, attrs['web_url'])
            new_issue.create_comment(comment_body)
    if issue.attributes['state'] == 'closed':
        # Close the issue if closed on GitLab
        new_issue.edit(state="closed")

for mr in mrs:
    attrs = mr.attributes
    new_pr = repo_gh.create_pull(title=attrs['title'],
                                 body=get_issue_body(mr, is_pr=True),
                                 head=attrs['source_branch'],
                                 base=attrs['target_branch'],
                                 maintainer_can_modify=True)
    for discussion in mr.discussions.list():
        if human_posted(discussion):
            comment_body = get_comment_body(discussion, attrs['web_url'])
            new_pr.create_issue_comment(comment_body)

from adaptive.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.