Octokit plugin to create a symlink to a file within the same repository
Browsers |
Load <script type="module">
import { Octokit } from "https://cdn.skypack.dev/@octokit/core";
import {
createSymlink,
composeCreateSymlink,
} from "https://cdn.skypack.dev/octokit-plugin-create-symlink";
</script> |
---|---|
Node |
Install with const { Octokit } = require("@octokit/core");
const {
createSymlink,
composeCreateSymlink,
} = require("octokit-plugin-create-symlink"); |
This plugin creates or updates a file (source) as a symlink which points to another file (target). It does not check whether the source or target file exists. If there is no change, an empty commit is created.
const MyOctokit = Octokit.plugin(createSymlink);
const octokit = new MyOctokit({ auth: "secret123" });
// the symlink file that will be created or updated
const sourcePath = "folder-with-symlinked-readme/README.md";
// path to the existing file or directory, relative from `sourcePath`.
const targetPath = "../README.md";
const { commit } = await octokit.createSymlink({
owner: "gr2m",
repo: "octokit-plugin-create-symlink",
sourcePath,
targetPath,
message: `Link ${sourcePath}`,
});
console.log("Symlink created via %s", commit.html_url);
When using the composeCreateSymlink
function, pass the octokit
instance as first argument.
const { commit } = await composeCreateSymlink(octokit, {
owner: "gr2m",
repo: "octokit-plugin-create-symlink",
sourcePath,
targetPath,
message: `Link ${targetPath} to ${targetPath}`,
});
console.log("Symlink created via %s", commit.html_url);
name | type | description |
---|---|---|
owner
|
string
|
Required. Repository owner login |
repo
|
string
|
Required. Repository name |
sourcePath
|
string
|
Required. The symlink file that will be created or updated |
targetPath
|
string
|
Required. Path to the existing file or directory, relative from `sourcePath`. |
message
|
string
|
Required. Commit message |
branch
|
string
|
Branch name to commit to. Defaults to the repository's default branch. |
See CONTRIBUTING.md