python操作github(github模块)
from github import Githubimport datetime# First create a Github instance:# using username and password#g = Github("$username", "$password")# or using an access token#g = Github("$token")# Github Enter
·
from github import Github
import datetime
# First create a Github instance:
# using username and password
#g = Github("$username", "$password")
# or using an access token
#g = Github("$token")
# Github Enterprise with custom hostname
g = Github(base_url="https://git.$domain.com/api/v3", login_or_token="$token")
# 获取帐号下所有的repositories名字:
for repo in g.get_user().get_repos():
print(repo.name)
# 模糊查询带有qualys的repositories名字
#repositories = g.search_repositories(query='qualys')
#for repo in repositories:
# print(repo) # Repository(full_name="$username/qualys_solution")
# 获取组织(测试未通过)
#org = g.get_organization("$username")
# 获取对象
repo = g.get_repo("$username/$repositoriesName") # Repository(full_name="$username/qualys_solution")
# 打印对象的一些属性
#print(dir(repo))
def formatGMTime(timestamp):
GMT_FORMAT = '%a, %d %b %Y %H:%M:%S GMT'
local_time = datetime.datetime.strptime(timestamp, GMT_FORMAT) + datetime.timedelta(hours=8)
now = local_time.strftime("%Y%m%d%H%M%S")
return now
# 获取项目的tag版本标签
for i in repo.get_tags():
#for i in repo.get_releases():
#print(dir(i))
print( i.name) # v1.0
#print( i.last_modified) # Fri, 23 Oct 2020 04:21:50 GMT
#print( i.raw_data)
commit = i.commit # Commit(sha="7e700a25a6cb378d5c04d7cb3d616c14546d1c6b")
# print(commit.last_modified) # Fri, 23 Oct 2020 04:21:50 GMT
# print(commit.update()) # True
createTime = commit.stats.last_modified # # Fri, 23 Oct 2020 04:21:50 GMT
a = formatGMTime(createTime)
print (a) # 当前tag的时间戳 20201023122146
#print( i.etag) # W/"ee2a6ada459ea157854e6a13179b40e7"
#print( i.raw_headers)
#break
#repo.create_file("aa2/test1.txt", "test1", "test2", branch="master")
#contents = repo.get_contents("aa/fix_test.sh")
#print(contents.decoded_content.decode())
#print(dir(contents))
#
#contents = repo.get_contents("/opt/backend/gitFileDir/fix_test.sh", ref="test")
#repo.update_file(contents.path,
# "more tests",
# "more tests",
# contents.sha,
# branch="test")
#file_list = [
# '/opt/backend/gitFileDir/fix_test.sh'
#]
#
#
#master_ref = repo.get_git_ref('heads/master')
#master_sha = master_ref.object.sha
#base_tree = repo.get_git_tree(master_sha)
#
#
#commit_message = 'Add simple regression analysis'
#
#repo.create_git_commit(commit_message, base_tree, [])
#repo.push()
#
更多推荐
已为社区贡献6条内容
所有评论(0)