-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgh-digitalassets
More file actions
117 lines (98 loc) · 4.22 KB
/
gh-digitalassets
File metadata and controls
117 lines (98 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env python
# set -e
# echo "Hello gh-digitalassets!"
import argparse
from github import Github
import os
g = Github("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")
user = g.get_user()
parser = argparse.ArgumentParser(prog="digitalassets", description="Simple helper commands to interact with Github Repos")
# parser.add_argument("action",
# choices=["reponame","listcontents","uploadfile"],
# help="Operation on Github Repos")
# parser.add_argument("reponame")
subparser = parser.add_subparsers(dest='command',help="Testing help command")
reponame = subparser.add_parser("reponame")
createrepo = subparser.add_parser("createrepo",help="Testing help command")
####################
## empty repo command removed
# createemptyrepo = subparser.add_parser("createemprepo")
# createemptyrepo.add_argument("--reponame",type=str,required=True)
####################
createrepo.add_argument("--reponame",type=str,required=True,help="Give the name of the repo to be created")
createrepo.add_argument("--filepath",type=str,required=False,help= "Give a folder path to upload files. Not a required argument")
createrepo.add_argument("--empty",type=str,required=False,default="False",help="True if we need to create empty repo. By defualt False")
repo_name = 'ramchandra-ub/testrepo2'
repo = g.get_repo(repo_name)
args = parser.parse_args()
if args.command == "reponame":
print(repo.name)
# elif args.command == "createemprepo":
# ## create repo
# createdRepo = user.create_repo(args.reponame)
# print("Repo created with name "+ createdRepo.full_name)
if args.command == "createrepo":
## create repo
if args.empty == "True":
createdRepo = user.create_repo(args.reponame)
createdRepoName = g.get_repo(createdRepo.full_name)
else:
createdRepo = user.create_repo(args.reponame)
print("Repo created with name "+ createdRepo.full_name)
createdRepoName = g.get_repo(createdRepo.full_name)
## read file content
if os.path.isfile(args.filepath):
with open(args.filepath) as file:
fileContent = file.read()
## upload file to the repo
# createdRepoName.create_file("testfile.txt","create file",fileContent,branch="main")
createdRepoName.create_file(args.filepath.split('\\')[-1],"create file",fileContent,branch="main")
print("testfile created in the repo" + createdRepo.full_name)
if os.path.isdir(args.filepath):
allFiles = os.listdir(args.filepath)
print(allFiles)
for files in allFiles:
if files == ".git":
continue
with open((os.path.join(args.filepath,files))) as file:
fileContent = file.read()
## upload file to the repo
# createdRepoName.create_file("testfile.txt","create file",fileContent,branch="main")
createdRepoName.create_file(files,"create file",fileContent,branch="main")
print("All files in the specified directory uploaded")
# elif args.action == "listcontents":
# contents = repo.get_contents("")
# for content_file in contents:
# print(content_file)
# elif args.action == "uploadfile":
# try:
# repo.create_file("test1.py", "test", "test", branch="main")
# except:
# print("File already exists. Change the file name")
# Snippets to help get started:
# Determine if an executable is in the PATH
# if ! type -p ruby >/dev/null; then
# echo "Ruby not found on the system" >&2
# exit 1
# fi
# Pass arguments through to another command
# gh issue list "$@" -R cli/cli
# Using the gh api command to retrieve and format information
# QUERY='
# query($endCursor: String) {
# viewer {
# repositories(first: 100, after: $endCursor) {
# nodes {
# nameWithOwner
# stargazerCount
# }
# }
# }
# }
# '
# TEMPLATE='
# {{- range $repo := .data.viewer.repositories.nodes -}}
# {{- printf "name: %s - stargazers: %v\n" $repo.nameWithOwner $repo.stargazerCount -}}
# {{- end -}}
# '
# exec gh api graphql -f query="${QUERY}" --paginate --template="${TEMPLATE}"