Skip to content

Commit

Permalink
Use correct URLs for bitbucket projects
Browse files Browse the repository at this point in the history
  • Loading branch information
Fraz committed Nov 25, 2014
1 parent cbeced3 commit 5d57b60
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 18 deletions.
11 changes: 7 additions & 4 deletions resources/changelog.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
</head>
<body>
{{^to-build-num}}
<h1>Changelog for <a href="https://github.com/MailOnline/{{global.project-name}}/commits/{{to}}">{{to}}</a></h1>
<h1>Changelog for <a href="{{to-url}}">{{to}}</a></h1>
{{/to-build-num}}
{{#to-build-num}}
<h1>Changelog for build <a href="https://github.com/MailOnline/{{global.project-name}}/commits/{{to}}">{{to-build-num}}</a> created at {{to-time}}</h1>
<h1>Changelog for build <a href="{{to-url}}">{{to-build-num}}</a> created at {{to-time}}</h1>
<p>VCS tag: {{to}}
{{/to-build-num}}
{{^from-build-num}}
<h2>Changes since <a href="https://github.com/MailOnline/{{global.project-name}}/commits/{{from}}">{{from}}</a> (<a href="https://github.com/MailOnline/{{global.project-name}}/compare/{{from}}...{{to}}">diff</a>)</h2>
<h2>Changes since <a href="{{from-url}}">{{from}}</a> (<a
href="{{compare-url}}">diff</a>)</h2>
{{/from-build-num}}
{{#from-build-num}}
<h2>Changes since build <a href="https://github.com/MailOnline/{{global.project-name}}/commits/{{from}}">{{from-build-num}}</a> created at {{from-time}} (<a href="https://github.com/MailOnline/{{global.project-name}}/compare/{{from}}...{{to}}">diff</a>)</h2>
<h2>Changes since build <a
href="{{from-url}}">{{from-build-num}}</a> created at {{from-time}}
(<a href="{{compare-url}}">diff</a>)</h2>
<p>VCS tag: {{from}}
{{/from-build-num}}
{{#sections}}
Expand Down
2 changes: 1 addition & 1 deletion resources/commit.mustache
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<li><a href="https://github.com/MailOnline/{{project-name}}/commit/{{hash}}">{{hash}}</a> (<em>{{project-name}}</em>) {{date}} [{{commiter}}] <strong>{{{linked-subject}}}</strong>
<li><a href="{{url}}">{{hash}}</a> (<em>{{project-name}}</em>) {{date}} [{{commiter}}] <strong>{{{linked-subject}}}</strong>
<p>{{{linked-body}}}
</li>
5 changes: 3 additions & 2 deletions src/gargamel/bower.clj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
deps-after (:dependencies (config project-dir :rev to))
deps-changed (data/diff deps-before deps-after)
mods-changed (merge-with merge-versions (first deps-changed) (second deps-changed))
changes (grg/changelog from to {:dir project-dir :name (name project-name)})]
changes (grg/changelog from to {:dir project-dir :name (name project-name)
:remote-url (git/remote-url project-dir)})]
(if mods-changed
(concat changes
(flatten
Expand All @@ -48,4 +49,4 @@
from to))
(grg/create-html-changelog (grg/enrich-changelog
(changelog grg/proj-name source-path from to))
from to)))
from to source-path)))
21 changes: 19 additions & 2 deletions src/gargamel/git.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
(:require [gargamel.util :as util]
[clojure.java.shell :as sh]))

(defn real-project-name [pn]
(if (= pn "electrostatic") "f_electrostatic" pn))

This comment has been minimized.

Copy link
@benedekfazekas

benedekfazekas Nov 25, 2014

Contributor

if we ever want to go public with gargamel this should not happen


(defn checkout-project [mod-name repo]
(let [tmpdir (util/mk-tmp-dir (name mod-name))
tmpdir-name (.getAbsolutePath tmpdir)]
Expand All @@ -10,5 +13,19 @@
(sh/sh "git" "clone" repo tmpdir-name)
tmpdir))

(defn remote-url [source-dir]
(sh/sh "git" "config" "--get" "remote.origin.url" :dir source-dir))
(defn remote-url* [source-dir]
(:out (sh/sh "git" "config" "--get" "remote.origin.url" :dir source-dir)))

(def remote-url (memoize remote-url*))

(defn commit-url [source-dir project-name hash]
(let [project-name (real-project-name project-name)]
(if (re-find #"bitbucket" (remote-url source-dir) )
(format "https://bitbucket.org/MailOnline/%s/commits/%s" project-name hash)
(format "https://github.com/MailOnline/%s/commit/%s" project-name hash))))

(defn compare-url [source-dir project-name from to]
(let [project-name (real-project-name project-name)]
(if (re-find #"bitbucket" (remote-url source-dir))
(format "https://bitbucket.org/MailOnline/%s/branches/compare/%s..%s" project-name from to)
(format "http://github.com/MailOnline/%s/compare/%s...%s" project-name from to))))
23 changes: 14 additions & 9 deletions src/leiningen/gargamel.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
(ns leiningen.gargamel
(:require [clojure.java.shell :as sh]
[clojure.string :as str]
[stencil.core :as st])
[stencil.core :as st]
[gargamel.git :as git])
(:import [java.io File]))

(def ^:dynamic proj-name nil)
Expand Down Expand Up @@ -40,25 +41,29 @@
(map #(zipmap [:hash :commiter :refs :date :subject :body] %))
(map #(assoc % :hash (apply str (butlast (-> % :hash)))))
(map #(update-in % [:hash] str/replace #"\W" ""))
(map #(assoc % :project-name (:name project)))))
(map #(assoc % :project-name (:name project)))
(map #(assoc % :url (git/commit-url (:dir project) (:name project) (:hash %))))))

(defn render-html-changelog [from to changes]
(defn render-html-changelog [from to changes source-dir]
(let [[to-release to-build-num to-time] (str/split to #"-")
[from-release from-build-num from-time] (str/split from #"-")
from-params (if (and from-build-num from-time)
(merge {:from from}
{:from-release from-release
:from-build-num from-build-num
:from-time (str/replace from-time #"_" " time: ")})
{:from from})
:from-time (str/replace from-time #"_" " time: ") })
{:from from })
to-params (if (and to-build-num to-time)
(merge {:to to}
{:to-release to-release
:to-build-num to-build-num
:to-time (str/replace to-time #"_" " time: ")})
{:to to})]
(st/render-file "changelog" (merge {:sections (vals changes)
:global {:project-name proj-name}}
:global {:project-name proj-name}
:from-url (git/commit-url source-dir proj-name from)
:to-url (git/commit-url source-dir proj-name to)
:compare-url (git/compare-url source-dir proj-name from to)}
from-params to-params))))

(defn issues->links [commit]
Expand Down Expand Up @@ -106,20 +111,20 @@
(group-by create-section)
section-titles))

(defn create-html-changelog [changes from to]
(defn create-html-changelog [changes from to source-dir]
(let [to (or to "HEAD")
target-dir (File. target-path)]
(when-not (.exists target-dir)
(.mkdirs target-dir))
(spit (format "%s/changelog-%s-%s.html" target-path from to)
(render-html-changelog from to changes))))
(render-html-changelog from to changes source-dir))))

(defn gargamel-changelog [project-name path from to]
(binding [proj-name project-name
target-path path]
(println (format "Generating changelog for project %s between %s and %s" project-name from to))
(create-html-changelog (enrich-changelog (changelog from to {:name project-name :dir "."}))
from to)))
from to ".")))

(defn gargamel
"Generates html changelog file between to commits or tags
Expand Down

0 comments on commit 5d57b60

Please sign in to comment.