Many improvements and fixes to nimble publish.
* Fixed incorrect URL in packages.json when remote URL is an ssh URL. * Fixed cloning of packages fork after oauth introduction. * A new branch is now created for each package addition.
This commit is contained in:
parent
d349aa0169
commit
e2d959bf9c
1 changed files with 34 additions and 23 deletions
|
|
@ -4,7 +4,7 @@
|
||||||
## Implements 'nimble publish' to create a pull request against
|
## Implements 'nimble publish' to create a pull request against
|
||||||
## nim-lang/packages automatically.
|
## nim-lang/packages automatically.
|
||||||
|
|
||||||
import httpclient, base64, strutils, rdstdin, json, os, browsers
|
import httpclient, base64, strutils, rdstdin, json, os, browsers, times, uri
|
||||||
import tools, nimbletypes
|
import tools, nimbletypes
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
@ -55,12 +55,12 @@ proc createFork(a: Auth) =
|
||||||
discard postContent("https://api.github.com/repos/nim-lang/packages/forks",
|
discard postContent("https://api.github.com/repos/nim-lang/packages/forks",
|
||||||
extraHeaders=createHeaders(a))
|
extraHeaders=createHeaders(a))
|
||||||
|
|
||||||
proc createPullRequest(a: Auth; packageName: string) =
|
proc createPullRequest(a: Auth, packageName, branch: string) =
|
||||||
echo("Creating PR")
|
echo("Creating PR")
|
||||||
discard postContent("https://api.github.com/repos/nim-lang/packages/pulls",
|
discard postContent("https://api.github.com/repos/nim-lang/packages/pulls",
|
||||||
extraHeaders=createHeaders(a),
|
extraHeaders=createHeaders(a),
|
||||||
body="""{"title": "Add package $#", "head": "$#:master",
|
body="""{"title": "Add package $1", "head": "$2:$3",
|
||||||
"base": "master"}""" % [packageName, a.user])
|
"base": "master"}""" % [packageName, a.user, branch])
|
||||||
|
|
||||||
proc `%`(s: openArray[string]): JsonNode =
|
proc `%`(s: openArray[string]): JsonNode =
|
||||||
result = newJArray()
|
result = newJArray()
|
||||||
|
|
@ -131,26 +131,29 @@ proc publish*(p: PackageInfo) =
|
||||||
createFork(auth)
|
createFork(auth)
|
||||||
echo "waiting 10s to let Github create a fork ..."
|
echo "waiting 10s to let Github create a fork ..."
|
||||||
os.sleep(10_000)
|
os.sleep(10_000)
|
||||||
if dirExists(pkgsDir):
|
|
||||||
pkgsDir = readLineFromStdin("Directory where to clone into: ")
|
echo "... done"
|
||||||
if pkgsDir.len == 0: userAborted()
|
if dirExists(pkgsDir):
|
||||||
echo "... done; cloning packages into: ", pkgsDir
|
echo("Removing old packages fork git directory.")
|
||||||
cd getTempDir():
|
removeDir(pkgsDir)
|
||||||
doCmd("git clone https://github.com/" & auth.user & "/packages " & pkgsDir)
|
echo "Cloning packages into: ", pkgsDir
|
||||||
# Use SSH instead of HTTPS so that the user isn't bothered with the
|
doCmd("git clone git@github.com:" & auth.user & "/packages " & pkgsDir)
|
||||||
# password for 'git push':
|
# Make sure to update the clone.
|
||||||
doCmd("git remote set-url origin git@github.com:$1/packages.git" %
|
echo("Updating the fork...")
|
||||||
auth.user)
|
cd pkgsDir:
|
||||||
elif not dirExists(pkgsDir):
|
doCmd("git pull https://github.com/nim-lang/packages.git master")
|
||||||
pkgsDir = readLineFromStdin("According to github, you already forked " &
|
doCmd("git push origin master")
|
||||||
"nim-lang/packages.\n" &
|
|
||||||
"Please give the path to it: ")
|
|
||||||
if pkgsDir.len == 0: userAborted()
|
|
||||||
if not dirExists(pkgsDir):
|
if not dirExists(pkgsDir):
|
||||||
raise newException(NimbleError,
|
raise newException(NimbleError,
|
||||||
"Cannot find nimble-packages-fork git repository. Stopping.")
|
"Cannot find nimble-packages-fork git repository. Cloning failed.")
|
||||||
|
|
||||||
|
if not fileExists(pkgsDir / "packages.json"):
|
||||||
|
raise newException(NimbleError,
|
||||||
|
"No packages file found in cloned fork.")
|
||||||
|
|
||||||
# We need to do this **before** the cd:
|
# We need to do this **before** the cd:
|
||||||
|
# Determine what type of repo this is.
|
||||||
var url = ""
|
var url = ""
|
||||||
var downloadMethod = ""
|
var downloadMethod = ""
|
||||||
if dirExists(os.getCurrentDir() / ".git"):
|
if dirExists(os.getCurrentDir() / ".git"):
|
||||||
|
|
@ -159,8 +162,14 @@ proc publish*(p: PackageInfo) =
|
||||||
url = output.string.strip
|
url = output.string.strip
|
||||||
if url.endsWith(".git"): url.setLen(url.len - 4)
|
if url.endsWith(".git"): url.setLen(url.len - 4)
|
||||||
downloadMethod = "git"
|
downloadMethod = "git"
|
||||||
|
let parsed = parseUri(url)
|
||||||
|
if parsed.scheme == "":
|
||||||
|
# Assuming that we got an ssh write/read URL.
|
||||||
|
let sshUrl = parseUri("ssh://" & url)
|
||||||
|
url = "https://github.com/" & sshUrl.port & sshUrl.path
|
||||||
elif dirExists(os.getCurrentDir() / ".hg"):
|
elif dirExists(os.getCurrentDir() / ".hg"):
|
||||||
downloadMethod = "hg"
|
downloadMethod = "hg"
|
||||||
|
# TODO: Retrieve URL from hg.
|
||||||
else:
|
else:
|
||||||
raise newException(NimbleError,
|
raise newException(NimbleError,
|
||||||
"No .git nor .hg directory found. Stopping.")
|
"No .git nor .hg directory found. Stopping.")
|
||||||
|
|
@ -173,10 +182,12 @@ proc publish*(p: PackageInfo) =
|
||||||
|
|
||||||
cd pkgsDir:
|
cd pkgsDir:
|
||||||
editJson(p, url, tags, downloadMethod)
|
editJson(p, url, tags, downloadMethod)
|
||||||
|
let branchName = "add-" & p.name & getTime().getGMTime().format("HHmm")
|
||||||
|
doCmd("git checkout -B " & branchName)
|
||||||
doCmd("git commit packages.json -m \"Added package " & p.name & "\"")
|
doCmd("git commit packages.json -m \"Added package " & p.name & "\"")
|
||||||
echo pkgsDir, " git push origin master"
|
echo("Pushing to remote of fork.")
|
||||||
doCmd("git push " & getPackageOriginUrl(auth) & " master")
|
doCmd("git push " & getPackageOriginUrl(auth) & " " & branchName)
|
||||||
createPullRequest(auth, p.name)
|
createPullRequest(auth, p.name, branchName)
|
||||||
echo "Pull request successful."
|
echo "Pull request successful."
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue