Permalink
Browse files

Owner can be different than user

  • Loading branch information...
1 parent 7939d3a commit 6f427bba07a0a8dfa8b0f9b2ec2f1be5087f9bb9 @dakrone committed Mar 7, 2012
Showing with 9 additions and 2 deletions.
  1. +1 −0 README.md
  2. +8 −2 src/gh_upload/core.clj
View
@@ -5,6 +5,7 @@
% export GHUSER=dakrone
% export GHREPO=cheshire
+% export GHREPOOWNER=dakrone
% export GHPASS=mysupersecretpassword
% java -jar gh-upload-1.0-standalone.jar /path/to/file.data
View
@@ -11,28 +11,34 @@
(or (System/getenv "GHPASS")
(throw (Exception. "Need $GHPASS set to Github password."))))
+(defn get-repo-owner []
+ (or (System/getenv "GHREPOOWNER")
+ (throw (Exception. "Need $GHREPOOWNER set to Github repository owner."))))
+
(defn get-repo []
(or (System/getenv "GHREPO")
(throw (Exception. "Need $GHREPO set to Github repository."))))
(defn delete-if-exists [filename]
(println "Checking if file already exists...")
(let [user (get-user)
+ owner (get-repo-owner)
repo (get-repo)
opts {:auth (str user ":" (get-password))}
basename (.getName (file filename))
- downloads (repo/downloads user repo)
+ downloads (repo/downloads owner repo)
id (first (map :id (filter #(= (:name %) basename) downloads)))]
(when id
(println "Deleting existing file...")
(repo/delete-download (get-user) (get-repo) id opts))))
(defn upload-file [filename]
(let [user (get-user)
+ owner (get-repo-owner)
repo (get-repo)
opts {:auth (str user ":" (get-password))}
_ (delete-if-exists filename)
- resp (repo/download-resource user repo filename opts)]
+ resp (repo/download-resource owner repo filename opts)]
(println (str "Uploading file " filename "..."))
(repo/upload-file resp)))

0 comments on commit 6f427bb

Please sign in to comment.