Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@changesets/get-github-info

changesets1.2mMIT0.6.0TypeScript support: included

Get the GitHub username and PR number from a commit. Intended for use with changesets.

readme

@changesets/get-github-info

View changelog

Get the GitHub username and PR number from a commit. Intended for use with changesets.

Getting Started

Note: This assumes you already have changesets setup.

To use @changesets/get-github-info, you'll need to install it and you'll probably also want dotenv to provide a GitHub personal access token via a .env file.

yarn add --dev @changesets/get-github-info dotenv

or

npm install --save-dev @changesets/get-github-info dotenv

Then you can use it in your .changeset/config.js like this.

require("dotenv").config();
const { getInfo } = require("@changesets/get-github-info");

// ...

const getReleaseLine = async (changeset, type) => {
  const [firstLine, ...futureLines] = changeset.summary
    .split("\n")
    .map((l) => l.trimRight());
  // getInfo exposes the GH username and PR number if you want them directly
  // but it also exposes a set of links for the commit, PR and GH username
  let { user, pull, links } = await getInfo({
    // replace this with your own repo
    repo: "Noviny/changesets",
    commit: changeset.commit,
  });
  let returnVal = `- ${links.commit}${
    links.pull === null ? "" : ` ${links.pull}`
  }${links.user === null ? "" : ` Thanks ${links.user}!`}: ${firstLine}`;
  if (futureLines.length > 0) {
    returnVal += `\n${futureLines.map((l) => `  ${l}`).join("\n")}`;
  }
  return returnVal;
};

// ...

You'll need to get a GitHub personal access token with read:user and repo:status permissions, and add it to a .env file.

GITHUB_TOKEN=token_here

You can now bump your packages and changelogs with changeset version and it'll have the GitHub info. 🎉

API

type Info = {
  user: string | null;
  pull: number | null;
  links: {
    commit: string;
    pull: string | null;
    user: string | null;
  };
};

type Options = {
  commit: string;
  repo: string;
};

export function getInfo(options: Options): Info {
  // magic...
}

changelog

@changesets/get-github-info

0.6.0

Minor Changes

  • #1185 a971652 Thanks @Andarist! - package.json#exports have been added to limit what (and how) code might be imported from the package.

0.5.2

Patch Changes

  • #1035 b360d50 Thanks @Kikobeats! - Improved the error message for a missing GITHUB_TOKEN to include the information about the required permissions.

0.5.1

Patch Changes

  • #820 a22eb8c Thanks @Andarist! - Errors resulting from the GitHub API calls should now be properly raised.

0.5.0

Minor Changes

0.4.5

Patch Changes

0.4.4

Patch Changes

  • f24f722 #444 Thanks @Andarist! - Changed the way how requests to the GitHub API were authenticated - from a query parameter to the Authorization header. The previously used method has been deprecated by the GitHub and will stop working in 2021.

0.4.3

Patch Changes

0.4.2

Patch Changes

0.4.1

Patch Changes

0.4.0

Minor Changes

  • 938823f #224 - Show the PR author of a change rather than the author of the commit that added a changeset to account for cases when maintainers add a changeset to a PR and merge the PR with a merge commit

Patch Changes

  • 938823f #224 - Fix cases where the wrong PR is returned when a commit is associated with multiple PRs

0.3.0

Minor Changes

Patch Changes

0.2.1

Patch Changes

  • 179433e #143 Thanks @mitchellhamilton! - Change query so it works on GitHub Actions and can get the author of a commit even if there isn't an associated pull request

0.2.0

Minor Changes

  • 296a6731 - Safety bump: Towards the end of preparing changesets v2, there was a lot of chaos - this bump is to ensure every package on npm matches what is found in the repository.

0.1.5

Patch Changes

  • a15abbf9 - Previous release shipped unbuilt code - fixing that

0.1.3

Patch Changes

0.1.2

Patch Changes

  • a966701d - Add repository information to package.json

0.1.1

Patch Changes

  • e0328dc0 - Previous publish was missing dist, publish with dist.

0.1.0

Minor Changes