Skip to content

Instantly share code, notes, and snippets.

@tmcw tmcw/core.clj forked from anonymous/core.clj
Created May 8, 2017

What would you like to do?
Find all repositories owned by a user, generate redirects from their gh-pages branches on a custom domain to a bare pages domain.
(ns gh-finder.core
(:require [tentacles.repos :as repos])
(:require [ :as io])
(:require [clj-yaml.core :as yaml])
(defn auth
"get an authentication token from the environment"
{:auth (System/getenv "GITHUB_TOKEN")})
(defn make-redirect
"given a repository, build a redirect to its address"
(spit (str "2017-01-01-" (:name repo) ".md")
(str "---\n"
(yaml/generate-string {
:layout "redirect_external"
:categories "redirect"
:permalink (str "/" (:name repo) "/")
:redirect (str "" (:name repo))
}) "---")))
(defn get-branches
"get branches given a repository map"
(some (partial = "gh-pages")
(map :name (repos/branches
(:login (:owner repo))
(:name repo)
(defn -main
"print a list of repositories you own that have gh-pages branches"
[& args]
(merge (auth) {:all-pages true})
(repos/user-repos "tmcw")
(map get-branches)
(remove nil?)
(map make-redirect)
;; (map (partial format "- %s"))
;; (clojure.string/join "\n")
;; (print)
(defproject gh-finder "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url ""
:license {:name "Eclipse Public License"
:url ""}
:dependencies [
[clj-yaml "0.4.0"]
[hiccup "1.0.5"]
[irresponsible/tentacles "0.6.1"]
[org.clojure/clojure "1.8.0"]]
:plugins [[lein-cljfmt "0.5.6"]]
:main ^:skip-aot gh-finder.core
:target-path "target/%s"
You can’t perform that action at this time.