Skip to content
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

Placeholder for hash of current commit in README.md file #1363

Open
mkczyk opened this issue Jul 7, 2020 · 8 comments
Open

Placeholder for hash of current commit in README.md file #1363

mkczyk opened this issue Jul 7, 2020 · 8 comments

Comments

@mkczyk
Copy link

mkczyk commented Jul 7, 2020

Preface

To link to specific file in README.md we have some several ways (#1, #2):

1. Link to latest version of file in specific branch:

https://github.com/mkczyk/test-experiment/blob/master/index.html

2. Permanent link to specific version (commit) of file:

https://github.com/mkczyk/test-experiment/blob/d7a4c7953d2b9084ca520eeb4434dd6d6689880d/index.html

We have to know SHA of commit, so it is not possible to place this link in README.me in the same commit (we don't know what hash will be generated).

3. Relative link do file.

Markdown:

[index.html](index.html)

This will be dynamically replaced with (rendered):

https://github.com/mkczyk/test-experiment/blob/d7a4c7953d2b9084ca520eeb4434dd6d6689880d/index.html

Feature request

I would like to be able to specify a placeholder that would be automatically replaced with the current hash of current commit.

For example.
Markdown:

This commit have hash: {current-commit-id}

Rendered:

This commit have hash: d7a4c7953d2b9084ca520eeb4434dd6d6689880d

Related issue/feature

I know that there was related feature request #913 (#472) with placeholder for branch name. And as I understood this isn't easy to implement.

But this issue refers to SHA of commit, not branch name. This feature looks looks similar to relative link do file (the 3. way to create a link).

Rendering from/to exists:

[index.html](index.html)
https://github.com/mkczyk/test-experiment/blob/d7a4c7953d2b9084ca520eeb4434dd6d6689880d/index.html

Maybe rendering from/to is easier to implement than rendering branch name:

{current-commit-id}
d7a4c7953d2b9084ca520eeb4434dd6d6689880d

Motivation for requesting feature

Primary motivation

I'm looking for a way to show demo of my HTML/JS code, separately for every commit (not only for last version of file).

I've researched several ways here:
https://stackoverflow.com/questions/62740362/how-to-show-demo-with-html-and-javascript-d3-js-on-github-for-every-commit

It seems that closest to success is using external service for serving HTML directly from GitHub file. There are several services of that kind: HtmlPreview, RawGit, raw.githack.com.

Example link for preview of HTML file (specific version of file):

https://rawcdn.githack.com/mkczyk/test-experiment/d7a4c7953d2b9084ca520eeb4434dd6d6689880d/index.html

You can see I need hash to create this link (I want to place this link in README.md).

If the placeholder existed I could easily create link.
Markdown:

https://rawcdn.githack.com/mkczyk/test-experiment/{current-commit-id}/index.html

Rendered:

https://rawcdn.githack.com/mkczyk/test-experiment/d7a4c7953d2b9084ca520eeb4434dd6d6689880d/index.html

With this you can see demo for every historical commit.

Secondary motivation

In this related issue #913 motivation is sending branch name to external service. If he could send hash of commit, maybe he can easily get branch name in external tool (there you usually have access to the entire Git repository) and it could be sufficient to archive his goal.

Another variant of feature request

If this is hard to implement I got an idea that can be easier to implement: relative link as text.

If this:

[index.html](index.html)

can be rendered to:

https://github.com/mkczyk/test-experiment/blob/d7a4c7953d2b9084ca520eeb4434dd6d6689880d/index.html

and more specifically (in view) to:

<a href="/mkczyk/test-experiment/blob/d7a4c7953d2b9084ca520eeb4434dd6d6689880d/index.html">index.html</a>

Maybe this can be rendered in view just as plain text?

/mkczyk/test-experiment/blob/d7a4c7953d2b9084ca520eeb4434dd6d6689880d/index.html

For example placeholder: {raw-url}.

With this I could build this URL:

https://rawcdn.githack.com{raw-url}

That will be rendered as:

https://rawcdn.githack.com/mkczyk/test-experiment/blob/d7a4c7953d2b9084ca520eeb4434dd6d6689880d/index.html

And this will also solve my problem.

(Bad) shortcut for implementing another variant

I've got another idea (that doesn't seem good).
If this / is rendered on view like this:

[index.html](index.html)
<a href="/mkczyk/test-experiment/blob/d7a4c7953d2b9084ca520eeb4434dd6d6689880d/index.html">index.html</a>

Maybe it would be enough to support custom <base> tag.
For example configuring this in README.md:

<base href="https://rawcdn.githack.com">

And markdown with relative link:

[index.html](index.html)

will be rendered as:

<a href="/mkczyk/test-experiment/blob/d7a4c7953d2b9084ca520eeb4434dd6d6689880d/index.html">index.html</a>

But clicking on it redirect to:

https://rawcdn.githack.com/mkczyk/test-experiment/blob/d7a4c7953d2b9084ca520eeb4434dd6d6689880d/index.html

Instead of standard this:

https://github.com/mkczyk/test-experiment/blob/master/index.html

Supporting <base> tag was mentioned here #84 (comment), but I think the same it is not good idea (Because what about the rest of the relative links? It will be broken).

@koraa
Copy link

koraa commented Jun 23, 2021

I would like to second this request, and add the following use case:

As the author of a paper whose drafts I share publicaly on github, I would like to include a Cite Me section in the readme. There I would like to share a github code block of a BibText file as well as a rendered text indicating how one may cite the draft. Both blocks should contain the short version of the revision being quoted as well as the comitt date.

@danisztls
Copy link

This would be really useful. And I also would like to reference past commits in a similar way.

Example: {{ HEAD^2 }}

@cpsauer
Copy link

cpsauer commented Jan 26, 2022

This would be super handy for commit-based package management, like for example, in Bazel WORKSPACEs

@bowbahdoe
Copy link

This would be useful for clojure deps.edn projects, where dependency information can be shared as

{:git/sha "abcdefg"}

@milesrichardson
Copy link

This would be really useful. And I also would like to reference past commits in a similar way.

Example: {{ HEAD^2 }}

Yes please. I got here from Google, looking for this feature.

Referencing past commits with relative references would be a nice feature in commit messages. The problem with SHA references is that once you rebase the branch (perhaps after every PR depending on GitHub workflow), the SHA changes. This is mostly okay as long as we can link to commits with an orphaned SHA, but I'm not sure if that's alway the case with the GitHub implementation of rebasing.

@judepayne
Copy link

I would also like to see this feature for my Clojure/script and babashka projects where it's common to use the GitHub sha as part of the dependencies information.

Example: {{ HEAD^2 }} would be great

Also a way of referring to the sha of a specified tag

Example: {{ TAG-SHA^0.0.4 }}

@amal
Copy link

amal commented Apr 25, 2023

It can really help to show the exact version for the snapshot builds (from JitPack or others similar), conveniently for the user.
I need short (7 chars) hash for it.

@wernerand
Copy link

This would be great for github-actions as you can go to a specific version and just grab the full SHA from readme. Trusting tags is a bit unsafe sometimes since you have no control over it but pinning a github-action to a specific has a bigger guarantee.
Also makes it easier to specify an action on a random commit that you might want instead of the release one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants