packages feed

github-backup 1.20120131 → 1.20120313

raw patch · 6 files changed

+39/−31 lines, 6 filesdep ~github

Dependency ranges changed: github

Files

Github/Data/Readable.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE StandaloneDeriving #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}  -- | This module re-exports the @Github.Data.Definitions@ module, adding -- instances of @Read@ to it.@@ -8,5 +9,5 @@ import Github.Data.Definitions  deriving instance Read GithubDate-deriving instance Read GithubUser+deriving instance Read GithubOwner deriving instance Read Repo
Makefile view
@@ -1,4 +1,4 @@-BASEFLAGS=-Wall -fno-warn-orphans+BASEFLAGS=-Wall GHCFLAGS=-O2 $(BASEFLAGS) bins=github-backup mans=github-backup.1
README.md view
@@ -19,7 +19,7 @@   from GitHub to back up that repository.    Or, run `github-backup username` to clone and back up all of a GitHub-  user's repositories.+  user's repositories. (Also works for organization names.)  ## Why backup GitHub repositories @@ -36,13 +36,13 @@  Each time you run github-backup, it will find any new forks on GitHub. It will add remotes to your repository for the forks, using names like-`github_linus_divemonitor`. It will fetch from every fork.+`github_torvalds_subsurface`. It will fetch from every fork.  It downloads metadata from each fork. This is stored into a branch named "github". Each fork gets a directory in there,-like `linus_divemonitor`. Inside the directory there will be some-files, like `linus_divemonitor/watchers`. There may be further-directories, like for comments: `linus_divemonitor/comments/1`.+like `torvalds_subsurface`. Inside the directory there will be some+files, like `torvalds_subsurface/watchers`. There may be further+directories, like for comments: `torvalds_subsurface/comments/1`.  You can follow the commits to the github branch to see what information changed on GitHub over time.@@ -55,6 +55,9 @@ github-backup is repository-focused. It does not try to back up other information from GitHub. In particular, social network stuff, like users who are following you, is not backed up.++github-backup does not log into git, so it cannot backup private+repositories.  github-backup will find and backup forks of a repository, and all forks of those forks, etc. However, it cannot go *up* the fork tree. So if
github-backup.1 view
@@ -3,7 +3,7 @@ .SH NAME github-backup \- backs up data from GitHub .SH SYNOPSIS-.B github-backup [\fIusername\fP]+.B github-backup [\fIusername\fP|\fIorganization\fP] .SH DESCRIPTION .I github-backup is a simple tool you run in a git repository you cloned from@@ -12,6 +12,7 @@ and watchers. .PP Alternately, if you pass it the username of a GitHub user, it will check-out, and back up, all that user's repositories.+out, and back up, all that user's repositories. (Also works to pass+the name of an organization using GitHub.) .SH AUTHOR  Joey Hess <joey@kitenet.net>
github-backup.cabal view
@@ -1,5 +1,5 @@ Name: github-backup-Version: 1.20120131+Version: 1.20120313 Cabal-Version: >= 1.6 License: GPL Maintainer: Joey Hess <joey@kitenet.net>@@ -26,7 +26,7 @@   Main-Is: github-backup.hs   Build-Depends: MissingH, hslogger, directory, filepath, containers, mtl,    network, extensible-exceptions, unix, bytestring, base < 5,-   IfElse, pretty-show, github+   IfElse, pretty-show, github >= 0.2.1  source-repository head   type: git
github-backup.hs view
@@ -41,7 +41,7 @@  toGithubUserRepo :: Github.Repo -> GithubUserRepo toGithubUserRepo r = GithubUserRepo -	(Github.githubUserLogin $ Github.repoOwner r)+	(Github.githubOwnerLogin $ Github.repoOwner r) 	(Github.repoName r)  repoUrl :: GithubUserRepo -> String@@ -71,7 +71,7 @@ data BackupState = BackupState 	{ failedRequests :: S.Set Request 	, retriedRequests :: S.Set Request-	, backupRepo :: Git.Repo+	, gitRepo :: Git.Repo 	}  {- Our monad. -}@@ -85,7 +85,7 @@ 	)  inRepo :: (Git.Repo -> IO a) -> Backup a-inRepo a = liftIO . a =<< getState backupRepo+inRepo a = liftIO . a =<< getState gitRepo  failedRequest :: Request -> Github.Error-> Backup () failedRequest req e = unless (ignorable e) $ do@@ -219,17 +219,17 @@  workDir :: Backup FilePath workDir = (</>)-		<$> (Git.gitDir <$> getState backupRepo)+		<$> (Git.gitDir <$> getState gitRepo) 		<*> pure "github-backup.tmp"  storeSorted :: Ord a => Show a => FilePath -> Request -> [a] -> Backup () storeSorted file req val = store file req (sort val)  gitHubRepos :: Backup [Git.Repo]-gitHubRepos = fst . unzip . gitHubPairs <$> getState backupRepo+gitHubRepos = fst . unzip . gitHubPairs <$> getState gitRepo  gitHubRemotes :: Backup [GithubUserRepo]-gitHubRemotes = snd . unzip . gitHubPairs <$> getState backupRepo+gitHubRemotes = snd . unzip . gitHubPairs <$> getState gitRepo  gitHubPairs :: Git.Repo -> [(Git.Repo, GithubUserRepo)] gitHubPairs = filter (not . wiki ) . mapMaybe check . Git.Types.remotes@@ -288,7 +288,7 @@ commitWorkDir :: Backup () commitWorkDir = do 	dir <- workDir-	r <- getState backupRepo+	r <- getState gitRepo 	let git_false_worktree ps = boolSystem "git" $ 		[ Param ("--work-tree=" ++ dir) 		, Param ("--git-dir=" ++ Git.gitDir r)@@ -301,7 +301,7 @@  updateWiki :: GithubUserRepo -> Backup () updateWiki fork = do-	remotes <- Git.remotes <$> getState backupRepo+	remotes <- Git.remotes <$> getState gitRepo 	if any (\r -> Git.remoteName r == Just remote) remotes 		then do 			_ <- fetchwiki@@ -424,12 +424,12 @@ newState :: Git.Repo -> BackupState newState = BackupState S.empty S.empty -backup :: Git.Repo -> IO ()-backup repo = evalStateT (runBackup go) . newState =<< Git.Config.read repo+backupRepo :: Git.Repo -> IO ()+backupRepo repo = evalStateT (runBackup go) . newState =<< Git.Config.read repo 	where 		go = do 			retriedfailed <- retry-			remotes <- gitHubPairs <$> getState backupRepo+			remotes <- gitHubPairs <$> getState gitRepo 			when (null remotes) $ 				error "no github remotes found" 			forM_ remotes $ \(r, remote) -> do@@ -437,12 +437,15 @@ 				gatherMetaData remote 			save retriedfailed -backupUser :: String -> IO ()-backupUser username = do-	repos <- either (error . show) id <$>-		Github.userRepos username Github.All+backupName :: String -> IO ()+backupName name = do+	userrepos <- either (const []) id <$>+		Github.userRepos name Github.All+	orgrepos <- either (const []) id <$>+		Github.organizationRepos name+	let repos = userrepos ++ orgrepos 	when (null repos) $-		error $ "No GitHub repositories found for user " ++ username+		error $ "No GitHub repositories found for " ++ name 	status <- forM repos $ \repo -> do 		let dir = Github.repoName repo 		unlessM (doesDirectoryExist dir) $ do@@ -453,17 +456,17 @@ 				, Param dir 				] 			unless ok $ error "clone failed"-		try (backup =<< Git.Construct.fromPath dir)+		try (backupRepo =<< Git.Construct.fromPath dir) 			:: IO (Either SomeException ()) 	unless (null $ lefts status) $ 		error "Failed to successfully back everything up. Run again later."  usage :: String-usage = "usage: github-backup [username]"+usage = "usage: github-backup [username|organization]"  main :: IO () main = getArgs >>= go 	where-		go [] = backup =<< Git.Construct.fromCwd-		go (username:[]) = backupUser username+		go [] = backupRepo =<< Git.Construct.fromCwd+		go (name:[]) = backupName name 		go _= error usage