GitHub relative internal repository links in PULL_REQUEST_TEMPLATE.md - github

Using a relative link as directed (https://help.github.com/articles/about-readmes/#relative-links-and-image-paths-in-readme-files) in a PULL_REQUEST_TEMPLATE.md does not relatively link correctly.
When viewed in an actual PR:

[CONTRIBUTING.md](/.github/CONTRIBUTING.md)
routes to: https://github.com/.github/CONTRIBUTING.md.
[CONTRIBUTING.md](.github/CONTRIBUTING.md)

[CONTRIBUTING.md](./.github/CONTRIBUTING.md)
route to:
https://github.com/owner/repo/compare/.github/CONTRIBUTING.md
instead of https://github.com/owner/repo/.github/CONTRIBUTING.md.
Changing to ../ to go up a level would work for PRs, but would break the link when viewed in the GitHub UI.
Clicking the link as viewed on GitHub works: https://github.com/fs-webdev/fs-dialog/blob/master/.github/PULL_REQUEST_TEMPLATE.md, just not inside a PR.
(I feel like this used to work in 2017)
What is the correct way to have the relative link function as expected in both cases?

Background
Unfortunately, the given implementation seems to consider only the current
URL instead of the actual file path in the repository.
The same limitation can be noted when creating issues (through e.g.:
https://github.com/owner/repo/issues/new):
[CONTRIBUTING.md](.github/CONTRIBUTING.md)
->
https://github.com/owner/repo/issues/.github/CONTRIBUTING.md
Workaround
I only managed to make the relative link work by specifying the full URL
path (including the leading /):
[CONTRIBUTING.md](/owner/repo/.github/CONTRIBUTING.md)
->
https://github.com/owner/repo/.github/CONTRIBUTING.md
With that said, the abstraction can only go up to the URL host (i.e.:
https://github.com).

Related

Any way to get a link to a GitHub action's latest result?

GitHub's Actions feature recently started letting users generate badges, to showcase the status of their tests. For example, if I have a set of tests that run on my repo's dev branch from a file named .github/test_dev.yml, I can access that build's status by adding /badge.svg to the end of the test's URL.
https://github.com/<username>/<repo_name>/actions/workflows/test_dev.yml/badge.svg
That's great from the standpoint of keeping your project readme up to date with the status of the project, but the next logical step would be to also add a link to the badge that points to the latest testing outcome.
Unfortunately, even though you can access all the tests of a particular action as follows:
https://github.com/<username>/<repo_name>/actions/workflows/test_dev.yml
The test runs themselves seem to be behind a unique ID under actions/runs/.
https://github.com/<username>/<repo_name>/actions/runs/1234567890
Is there any way to construct a URL that just points to the latest test? Something like:
https://github.com/<username>/<repo_name>/actions/workflows/test_dev.yml?result=latest
I poked through GitHub's documentation, but even though there's some documentation surrounding the generation of those badge SVG's, I couldn't find anything about linking directly to the action that actually generated that SVG.
you can use this to get the id in a yaml file:
https://github.com/<username>/<repo_name>/actions/runs/${{ github.run_id }}

Github not detecting an inner index.html

I'm publishing my own profile site on github on https://yilmazhasan.github.io/pwp
It was working before some changes, now it gives 404 for https://yilmazhasan.github.io/pwp/src/index.html although there is an index.html file.
I'm redirecting pwp/index.html to pwp/src/index.html, it sees first one but not second one.
Since it is public, they can be seen on https://github.com/yilmazhasan/pwp
What can be caused to this?
(Note: It works on localhost)
Even without redirecting pwp/index.html to pwp/src/index.html, you could simply change your publication folder to src, as seen here (for the docs folder, but the same idea applies)

GitHub hosted Jeykll site. Background images within css are not displaying?

I've created a settings.yml within a _data folder. This also contains my baseurl: /run-and-roll.
So I have inserted {{ site.data.settings.baseurl }} in front of my assets. The css file is loading along with images that are defined in the html. However, any background images requested in the css are not showing?
https://granttransition.github.io/run-and-roll/
Every configuration variable that appears in https://jekyllrb.com/docs/configuration/ makes sense to keep them there.
Usually templates preppend the base url when generating some urls like the ones of the assets, using {{site.baseurl}}, so if you manually sets it from another location it won't be used by default.
What you have read that is a good practice to have settings and config separate is for every other configuration not related exactly with jekyll built-in variables, that it is a good practice to put them on data files, so you keep your _conf.yml as clear as possible as the official docs suggests, that makes easier to maintain and update your Jekyll instance:
In addition to the built-in variables available from Jekyll, you can
specify your own custom data that can be accessed via the Liquid
templating system.
Jekyll supports loading data from YAML, JSON, and CSV files located in
the _data directory. Note that CSV files must contain a header row.
This powerful feature allows you to avoid repetition in your templates
and to set site specific options without changing _config.yml.
Plugins/themes can also leverage Data Files to set configuration
variables.
TL;DR
just put baseurl in _config.yml as suggested in other answers :)
b/c if you are using Jekyll with Github Page, then if site.url or site.baseurl are not specified, in a CNAME or config.yml, for the production build. then they will be set automatically by github page generator
Explanation
from github page generator code-source:
# Set `site.url` and `site.baseurl` if unset and in production mode.
def set_url_and_baseurl_fallbacks!
return unless Jekyll.env == "production"
repo = drop.send(:repository)
site.config["url"] ||= repo.url_without_path
if site.config["baseurl"].to_s.empty? && !["", "/"].include?(repo.baseurl)
site.config["baseurl"] = repo.baseurl
end
end
the default build environment for jekyll, is development. So while, working on your site locally. every thing will run just as you expect. even when putting baseurl in other location than _config.yml
but in github page side, the web site is built with this command:
JEKYLL_ENV=production jekyll build
and site.url and site.baseurl are overridden.
in your case, if you're using {{ site.data.settings.baseurl }} to access some page, and it's set to a value like ('' or '/') you may not notice a navigation issue. bat assets path for css and js will not work as expected.
So, just put baseurl in the _config.yml, refactor your layout and pages accordingly. and you'll be fine.
a side note: as mentioned in #David answer, it's the jekyll convention to put website setting. in _config.yml, but if you want to put them in other place, you can. just make sure, to declare them for the production build as will.
see also: Clearing Up Confusion Around baseurl -- Again
UPDATE
even after moving the website to a github project repo: /<user-name>.github.io/<repo-name> instead of user (or organization) repo: /<user-name>.github.io. you need to set as follows:
site.baseurl: ''
or just remove it. since you serve your website from the main repository (cf. above refence)
Use of {{ site.baseurl }} is a jekyll convention, moving it to a data file is not a good idea.
Nevertheless from your css standpoint, path to runner.jpg will always be ../assets/img/runner.jpg. No need to use baseurl.

gsutil setwebcfg weird sub folder behavior

It seems google cloud storage provides a different behavior whether a folder is access from a web client with or without a trailing /
A simple test shows a different behavior for the following link
http://gstest.tekartik.com/sub/dir (fail to load css - background is white)
http://gstest.tekartik.com/sub/dir/ (works ok - background is black)
Where the bucket has been configured using:
gsutil setwebcfg -m index.html -e 404.html gs://gstest.tekartik.com
For information it contains 3 simple files index.html/404.html/style.css where style.css only set the background to black.
They both correctly "redirect" to the url http://gstest.tekartik.com/sub/dir/index.html. However the relative path does not allow for style.css to be loaded properly in the first case.
What I would like is to have the 1st case to be redirected using a trailing / (which is what Amazon S3 does). What is needed for this to work propertly so that I can give a url to someone without worrying about whether the trailing / is entered?
as a side, this works fine as at the root level (http://gstest.tekartik.com/ got automatically renamed to http://gstest.tekartik.com as here the trailing / is not needed)
I've spoken with the engineering team and we agree this should work the way you expected. This will be fixed in the near term by adding a bucket configuration setting to enable the expected behavior (the extra config step is needed to avoid breaking any apps depending on the current behavior). We're also planning to make it easy to update the new config setting via gsutil. I can't say when exactly these changes will be available but tune into the gs-announce group to monitor these (and other) details about Google Cloud Storage. Thanks for bringing this to our attention.
Update (June 3, 2013): This has now been fixed in production.

Reference GitHub file in jsFiddle

Is there a possibility to misuse grab files from a github repo as external resources in jsFiddle?
TLDR; Visit rawgit.com which will pop your files on a CDN straight from GitHub so you can use them.
Unfortunately none of the answers here worked for me. The rawgithub URL didn't seem to work as the connection gets refused. So here's a full solution that did work. Firstly in GitHub you need to click the Raw button to get the original JavaScript.
Then copy the URL from the page it takes you too. You'll notice if you try and use this directly you'll get a warning from JSFiddle.
More to the point is the browser will give you an error, e.g.:
Refused to execute script from https://raw.githubusercontent.com/nnnick/Chart.js/master/Chart.min.js' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.
Take that URL and visit rawgit.com. This will give you a URL of the format https://rawgit.com/nnnick/Chart.js/master/Chart.min.js which you can then use.
I've tried and tested this and it seems to work fine without issue
This is an updated answer, since the url's have changed slightly for Github... I ran into this issue and figured it out for present day. Hopefully this helps people out finding this post recently. Example for Bootstrap Slate theme from Bootswatch:
Raw file url: https://raw2.github.com/thomaspark/bootswatch/gh-pages/slate/bootstrap.css
Remove the 2. after raw: https://rawgithub.com/thomaspark/bootswatch/gh-pages/slate/bootstrap.css
That's it! :D
Nowadays JSDelivr seems to be the best option.
UPDATE
How to use or misuse github as kind of a CDN is not a thought that only benign "fiddlers" have; criminals have that thought also. Unfortunately, github, being as free and as anonymous as it is, is prone to be misused. As far as I can tell, the fact that some of the above solutions are things which are now broken, has to do with that.
Here is how I do it. It works now (Nov 2019), but it's admittedly not very convenient.
Get a github account yourself, if you don't already have one. Create a repository the name of which is identical to your github user name. That repo (and only that repo), - I'll call it the "home repo" - you can use as your web hosting service. https : // yourGithubUserName .github.io will show your home repo "raw/as it is" to the public. (Folder contents is not shown, and you HAVE TO have an index.html)
Now, if you want to use someone else's github repo in a fiddle, just copy over the complete repo to your home repo, and then just reference your copy of that repo with the src attribute of a script tag in the HTML part of the fiddle. Like this:
<head>
<script src="https://mathheadinclouds.github.io/thirdparty/esprima.js"></script>
<script src="https://mathheadinclouds.github.io/thirdparty/estraverse.browser.js"></script>
<script src="https://mathheadinclouds.github.io/thirdparty/escope.browser.js"></script>
</head>
<body></body>
Above snippet shows the HTML part of a working fiddle which is using the node modules esprima, estraverse, and escope, which is to say, the github repos of the same name. thirdparty is there because that's the name of the subfolder (in my home repo) where I put the copies.
As I said, not very convenient (lot's of copy and paste to set it all up), but that's what works for me.
And I should mention, just copy/paste might not be enough, you might have to do browserify or webpack on the referenced repo (if it was made for node, that is.)
here is the fiddle I was talking about.
OLD ANSWER
(works, but is kind of slow)
You can use requirify. It's made to enable you to require (as it is in node) on the browser command line; but it works in fiddles too, I tested it. I have no clue if it's "the best", compared to the other methods above (since I didn't go through them all and tested them), but it works.
Here is an example fiddle loading esprima (javascript parser), then escodegen (reverse javascript parser depending on esprima), then parsing and regenerating some simple javascript code.
what
require('lorem', 'ipsum')
does is, it loads the ipsum node module from npm, and puts the result into global variable named lorem. So this is only for npm modules not general github files which aren't also node modules. Shouldn't be much restriction since you can always turn it into a node module if it's your own project.
here it is
second example using same technique.
(((it's actually even simpler as shown in the fiddle. You can just put the 2 require statements right one after the other, you don't need a callback function in between (just one callback function to wait until both are loaded))))
Another possibility is to add the Git library to the cdnJS Script Repository (they write that any library that is resonably popular on GitHub will be accepted) and then use it as external resource.
Just found out: there are lots of Javascript libraries at http://jsdb.io/ and it's very easy to add new ones there--i's just a matter of entering the URL of a Github repository.
If there is a git repo in following folder structure
fiddletest/test1 (fiddletest is the repo name and test1 is a folder)
then the corresponding jsfiddle link will be
http://jsfiddle.net/gh/get/<library name>/<version>/<github user name>/fiddletest/tree/master/test1/
The folder and file structure must be like this
fiddletest(the repo name)
|____ test1
|____ demo.html
|____ demo.js
|____ demo.css
|____ demo.details
except these three files others will be ignored.
the details file should hold the fiddle details and link of external resources(if any) as follows
---
name: test fiddle repo
description: this is a test repo
resources:
- http://abc.xyz.com/abc.js
- http://abc.xyz.com/abc2.js
...
May be you have noticed the and in the fiddle link. If a fiddle is with pure js the the library name should be "library" and the version should be "pure"
In a nutshell the fiddle link to reffer to github should be in following format
http://jsfiddle.net/gh/get/<library name>/<version>/<github user name>/<repo name>/tree/<branchname>/<folder name>/
2021
Just go to github file and click "Download" button and copy URL - it will works with fetch - working example here (it not works in SO snippet - I don't know why) - example url from this file:
https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/VC/glTF-Embedded/VC.gltf