Skip to content
Snippets Groups Projects
Select Git revision
  • 1dff73eba1642140bd5a2f11fb336ef3edb868b1
  • master default protected
2 results

gitlab_demo.py

Blame
  • Christopher Bohn's avatar
    Christopher Bohn authored
    Separating the api-level code from the automation code. Partly this is
    to avoid commingling the two types of code in the repo. Partly this is
    to facilitate re-use: the api functions will certainly be useful for
    other courses; the automation functions might be useful for other
    courses.
    1dff73eb
    History
    gitlab_demo.py 1.86 KiB
    from gitlab import Gitlab
    import gitlab_functions
    from config import Config
    from course import Course
    
    
    """
    def add_rubi(git_server):
        team_number = 99
        project_name = f'foo{team_number}'
        project = gitlab_functions.create_project_in_group(git_server, Course.gitlab_namespace, project_name)
        user = gitlab_functions.get_user_by_name(git_server, 'rubi.quinones')
        gitlab_functions.add_user_to_project_as_maintainer(project, user)
        team_number = 98
        project_name = f'bar{team_number}'
        project = gitlab_functions.create_project_in_group(git_server, Course.gitlab_namespace, project_name)
        user = gitlab_functions.add_user_to_project_as_maintainer(git_server, project, 'rubi.quinones')
        team_number = 97
        project_name = f'baz{team_number}'
        project = gitlab_functions.create_project_in_group(git_server, Course.gitlab_namespace, project_name)
        gitlab_functions.add_user_to_project_as_maintainer(git_server, project, user)
    """
    
    
    """
    def add_and_print_issues(git_server):
        project_name = f'{Course.gitlab_namespace}/baz97'
        project = gitlab_functions.get_project_by_path(git_server, project_name)
        issue1 = gitlab_functions.create_issue(project, 'Larry', 'Larry Fine')
        issue2 = gitlab_functions.create_issue(project, 'Moe', 'Moe Howard')
        issue3 = gitlab_functions.create_issue(project, 'Curly', 'Curly Howard')
    
        issue2.state_event = 'close'
        issue2.save()
    
        issues = gitlab_functions.get_issues(project)
        for issue in issues:
            if issue.closed_at is None:
                print(f'Issue #{issue.iid} created at {issue.created_at} and updated at {issue.updated_at}')
            else:
                print(f'Issue #{issue.iid} created at {issue.created_at} and closed at {issue.closed_at}')
    """
    
    
    if __name__ == '__main__':
        git = Gitlab(Config.gitlab_url, private_token=Config.gitlab_api_key)
        # add_rubi(git)
        # add_and_print_issues(git)