예제 #1
0
def get_clone_commands(token, repo_root):
    con = Gitlab("http://gitlab.your.domain", token)
    con.auth()

    for project in con.Project(per_page=200):
        url = project.ssh_url_to_repo

        subdir = url.split(":")[1].split("/")[0]
        cmd = "bash -c '(mkdir -p {repo_root}/{subdir} && cd {repo_root}/{subdir} && git clone {url})'".format(
            **locals())
        yield cmd
예제 #2
0
def GitLab_Work_Log(url, token):
    gl = Gitlab(url, token)
    gl.auth()
    work_log = ''
    for project in gl.Project():
        work_log += "Project Name: " + project.name + '\n'
        for commit in project.Commit():
            if commit.author_email == gl.user.email:
                commited_at = datetime.strptime(commit.created_at[:19], '%Y-%m-%dT%H:%M:%S')
                if datetime.today().date()-timedelta(1) == commited_at.date():
                    work_log += commit.message + '\n'

        for merge in project.MergeRequest():
            if merge.author.id == gl.user.id:
                merged_at = datetime.strptime(merge.created_at, '%Y-%m-%dT%H:%M:%S.%fZ')
                if datetime.today().date()-timedelta(1) == merged_at.date():
                    work_log += merge.title + '\n'

    return work_log
예제 #3
0
def crear_repo(package_name):
    md5hash_pn = md5(package_name).hexdigest()
    first_pref = md5hash_pn[0:2]
    second_pref = md5hash_pn[2:4]
    workingdir = root_git_dir + "/" + first_pref + "/" + second_pref + "/" + package_name
    if not (os.access(root_git_dir + "/" + first_pref, os.F_OK)):
        os.mkdir(root_git_dir + "/" + first_pref)
        os.mkdir(root_git_dir + "/" + first_pref + "/" + second_pref)
    elif not (os.access(root_git_dir + "/" + first_pref + "/" + second_pref,
                        os.F_OK)):
        os.mkdir(root_git_dir + "/" + first_pref + "/" + second_pref)
    repo = pygit2.init_repository(workingdir)
    dashed_package_name = package_name.replace('.', '-').lower()
    myRemote = repo.remotes.create(
        package_name, gitlab_url + '/marvin/' + dashed_package_name + '.git')
    gl = Gitlab(gitlab_url, gitlab_token)
    gl.auth()
    p = gl.Project({'name': package_name, 'public': True})
    p.save()
    return repo
예제 #4
0
def create_gitlab_project(
        default_has_issues, default_has_wiki, gitlab_secure_config,
        options, project, description, homepage):

    created = False
    has_issues = 'has-issues' in options or default_has_issues
    has_wiki = 'has-wiki' in options or default_has_wiki

    secure_config = ConfigParser.ConfigParser()
    secure_config.read(gitlab_secure_config)

    # Project creation doesn't work via oauth
    glab = Gitlab(secure_config.get("gitlab", "url"),
                  secure_config.get("gitlab", "key"))
    glab.auth()
    orgs = glab.Group()
    orgs_dict = dict(zip([o.name.lower() for o in orgs], orgs))

    # Find the project's repo
    project_split = project.split('/', 1)
    org_name = project_split[0]
    if len(project_split) > 1:
        repo_name = project_split[1]
    else:
        repo_name = project
        org_name = 'ustack'

    try:
        org = orgs_dict[org_name.lower()]
    except Exception:
        # we do not have control of this github org ignore the project.
        return False
    if glab.search_projects(repo_name):
        return created

    project_info = {'name': repo_name, 'namespace_id': org.id,
                    'wiki_enabled': has_wiki, 'description': description,
                    'issues_enabled': has_issues}
    glab.Project(project_info).save()
    created = True
    return created