-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow key '{git-commit}' for source URIs #170
Conversation
README.md
Outdated
* `{classpath}` - the relative path of the file within the source directory | ||
* `{line}` - the line number of the source file | ||
* `{version}` - the version of the project | ||
* `{git-commit-id}` - the Git commit id of the repository |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps change this to git-commit
instead. It saves a few characters, and it doesn't add ambiguity in context.
codox/src/codox/main.clj
Outdated
@@ -91,17 +93,41 @@ | |||
(apply text/read-documents) | |||
(sort-by :name)))) | |||
|
|||
(defn- git-commit-id [dir] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function tries to avoid exceptions, but this is the opposite of what we should be doing. Instead:
(defn git-commit [dir]
(let [{:keys [out exit err] :as result} (shell/sh "git" "rev-parse" "HEAD" :dir dir)]
(when (neg? exit) (throw (ex-info "Error getting git commit" result)
(when (str/blank? out) (throw (ex-info "Git commit number not found" result)
(str/trim out)))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking 'exit' is probably sufficient.
codox/src/codox/main.clj
Outdated
:exclude-vars #"^(map)?->\p{Upper}" | ||
:metadata {} | ||
:themes [:default] | ||
:git-commit-id (git-commit-id root-path)})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's change this to :git-commit
and then place it in a delay
so that repositories without a git project don't error.
codox/src/codox/writer/html.clj
Outdated
(str/replace "{basename}" (uri-basename path)) | ||
(str/replace "{line}" (str line)) | ||
(str/replace "{version}" version) | ||
(str/replace "{git-commit-id}" git-commit-id)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If git-commit
is a delay, we can deref
or force
it here.
Thanks for the patch. I added some review comments. Can you also ensure that your commit message follows the seven rules? |
Thank you for the comments. 'git-commit' is now a delay and only dereferenced if needed. It fails hard if we are not in a git repo. |
codox/src/codox/main.clj
Outdated
@@ -91,17 +93,25 @@ | |||
(apply text/read-documents) | |||
(sort-by :name)))) | |||
|
|||
(defn git-commit [dir] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make this private.
codox/src/codox/writer/html.clj
Outdated
(-> uri | ||
uri (if (map? source-uri) (get-source-uri source-uri path) source-uri) | ||
gc "{git-commit}" | ||
uri* (cond-> uri |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should avoid using cond->
for compatibility.
codox/src/codox/writer/html.clj
Outdated
uri (if (map? source-uri) (get-source-uri source-uri path) source-uri) | ||
gc "{git-commit}" | ||
uri* (cond-> uri | ||
(and (string? uri) (.contains uri gc)) (str/replace gc @git-commit))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to factor this out into a function. So:
(defn- force-replace [^String s match replacement]
(if (.contains s match)
(str/replace match (force replacement))
s))
example/project.clj
Outdated
@@ -14,7 +14,7 @@ | |||
:doc-files ["doc/intro.md" | |||
"doc/formatting.md"] | |||
:source-uri | |||
"https://github.com/weavejester/codox/blob/{version}/codox.example/{filepath}#L{basename}-{line}" | |||
"https://github.com/weavejester/codox/blob/{git-commit}/example/{filepath}#L{basename}-{line}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add this to a profile so that the {version}
key is still tested.
In source URIs the key '{git-commit}' is replaced with the Git commit id of the repository. See weavejester#168
Applied requested changes and removed "{git-commit}" from build.boot. |
The placeholder is replaced with the Git commit id of the repository.
Eg:
:codox
{:source-uri
"http://gerrit.mydomain.de/gitlist/myproject.git/blob/{git-commit-id}/{filepath}#L{line}"}
Will result in:
http://gerrit.mydomain.de/gitlist/myproject.git/blob/17073c0db441f5550a6cdbd1e5d2143ae6f5b576/src/de/mydomain/foo/bar.clj#L23
See
#168