Skip to content

Instantly share code, notes, and snippets.

@rodrigosiviero
Created January 22, 2020 12:53
Show Gist options
  • Select an option

  • Save rodrigosiviero/b3979cb460b24b8fab4961075093db84 to your computer and use it in GitHub Desktop.

Select an option

Save rodrigosiviero/b3979cb460b24b8fab4961075093db84 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import os
import gitlab
import click
#Creates a Gitlab Connection object
gl = gitlab.Gitlab('https://gitlab.example.com/gitlab', private_token=os.environ['your_token'])
#Creates a function to get the project internal ID from the CI.
def get_project(project_id):
return gl.projects.get(project_id)
#Creates the create_release function and decorate with Click.
@click.command()
@click.argument('project_id')
@click.argument('version')
def create_release(project_id, version):
#Gets the Project ID to be used later and stores to a variable.
project = get_project(project_id)
#defines the information to go to the release.
release_name = "My initial release"
description = "My awesome release notes"
#Creates the new release.
release = project.releases.create({'name': release_name, 'tag_name': version, 'description': description })
print(f'Created a new release with the tag: {tag_name} and project ID is: {project_id}')
if __name__ == '__main__':
create_release()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment