Tagging through API wrapper
This commit is contained in:
parent
8d99ffc87f
commit
9de30a1507
3 changed files with 30 additions and 0 deletions
2
Jenkinsfile
vendored
2
Jenkinsfile
vendored
|
@ -8,6 +8,7 @@ pipeline {
|
|||
}
|
||||
}
|
||||
steps {
|
||||
sh 'pip install -r requirements.txt'
|
||||
sh 'python -m py_compile sources/add2vals.py sources/calc.py'
|
||||
stash(name: 'compiled-results', includes: 'sources/*.py*')
|
||||
}
|
||||
|
@ -50,6 +51,7 @@ pipeline {
|
|||
agent any
|
||||
steps {
|
||||
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'git-credentials-id', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD']]) {
|
||||
sh("python sources/git_tagging.py ${env.GIT_USERNAME} ${env.GIT_PASSWORD} simple-python-pyinstaller-app")
|
||||
sh("git push https://${env.GIT_USERNAME}:${env.GIT_PASSWORD}@github.com/paolarozo/simple-python-pyinstaller-app.git --tags")
|
||||
}
|
||||
}
|
||||
|
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
requests
|
||||
pygithub
|
26
sources/git_tagging.py
Normal file
26
sources/git_tagging.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
import sys
|
||||
|
||||
from github import Github
|
||||
|
||||
|
||||
class RepositoryTagWrapper:
|
||||
def __init__(self, username, token, repo_name):
|
||||
self.username = username
|
||||
self.token = token
|
||||
self.repo_name = repo_name
|
||||
|
||||
def tag_repository(self):
|
||||
# github authentication through an access token
|
||||
github_obj = Github(self.token)
|
||||
# fetching the repository
|
||||
repository = github_obj.get_repo('repo/{}'.format(self.repo_name))
|
||||
# creating the tag
|
||||
new_tag = repository.create_git_tag('v.0.0.1', 'First tag', 'e4fc97dbb78a0c2d726b16ff29dc2a914db87fc7',
|
||||
'commit')
|
||||
# creating reference to the tag
|
||||
reference = repository.create_git_ref('refs/tags/v.0.1', new_tag.sha)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
repository_wrapper = RepositoryTagWrapper(sys.argv[0], sys.argv[1], sys.argv[2])
|
||||
repository_wrapper.tag_repository()
|
Loading…
Reference in a new issue