@invitation-homes/release-notes
Generates release notes from hosted services (such as GitHub and Jira) in one of the following formats:
Installation
First, make sure your home directory has a .npmrc
file with GitHub Personal Access Token:
//npm.pkg.github.com/:_authToken=<your_personal_access_token>
Note: your GitHub Personal Access Token needs at least "read" permissions for packages, and should be authorized for use with the Invitation Homes GitHub Organization.
Next, configure your project to use the GitHub Packages Registry for this package:
@invitation-homes:registry=https://npm.pkg.github.com
Then install:
yarn:
yarn add -D @invitation-homes/release-notes
Usage
Quick Start - Use built-in Configured Integrations!
Integrations save you time by fetching data for you from source control and project management tools.
Integration Type | Available Configured Integrations |
---|
Source Control | github |
Project Management Tool | jira |
Example: GitHub & Jira
Set the environment variables needed for the GitHub and Jira Configured Integrations:
SCM_TOKEN=<your_github_token>
PROJECT_MGMT_BASE_URL=<your_jira_base_url>
PROJECT_MGMT_USERNAME=<your_jira_username_or_email>
PROJECT_MGMT_TOKEN=<your_jira_api_token>
Generate the diff and format the output:
import * as releaseNotes from '@invitation-homes/release-notes';
import type { FetchCommitsIntegration, FetchStoryDataIntegration } from '@invitation-homes/release-notes';
async function createReleaseNotes(repository: string, start: string, end: string): Promise<string> {
const githubConfig: FetchCommitsIntegration = { source: 'github', repository, start, end };
const jiraConfig: FetchStoryDataIntegration = { source: 'jira' };
const outputFormat = 'md';
const version = '1.0.0';
const diff = await releaseNotes.generate(githubConfig, jiraConfig);
const output = releaseNotes.format(diff, outputFormat, {
name: `${repository} v${version}`,
repositoryOwner: 'invitation-homes',
repository,
});
return output;
}
GitHub
Required Environment Variables
Variable | Description |
---|
SCM_TOKEN | An API token for GitHub. Used to fetch commits from a repository for given start and end points. |
Jira
Required Environment Variables
Variable | Description |
---|
PROJECT_MGMT_BASE_URL | The base url of your Jira organization. |
PROJECT_MGMT_USERNAME | Jira username or email. |
PROJECT_MGMT_TOKEN | Jira API token associated with the username. |
Custom Configuration
If you're using a source control system or project management tool other than those provided as configured integrations, you can create custom configuration functions.
import * as releaseNotes from '@invitation-homes/release-notes';
import type { FetchCommits, FetchStoryData } from '@invitation-homes/release-notes';
async function createReleaseNotes(repository: string, start: string, end: string): Promise<string> {
const diff = await releaseNotes.generate(fetchCommits, fetchStoryData);
const output = releaseNotes.format(diff, 'md', {
name: `${repository} v1.0.0`,
repositoryOwner: 'invitation-homes',
repository,
});
return output;
}
async function fetchCommits(): FetchCommits {
}
async function fetchStoryData(storyId: string): FetchStoryData {
}
Custom Auth
If your workspace doesn't support environment variables, you can either (a) implement custom configuration/s, or (b) add a custom function to the configured integration that returns the necessary variables. For example:
import * as releaseNotes from '@invitation-homes/release-notes';
import type { FetchCommitsIntegration, FetchStoryDataIntegration } from '@invitation-homes/release-notes';
async function createReleaseNotes(repository: string, start: string, end: string): Promise<string> {
const githubConfig: FetchCommitsIntegration = {
source: 'github',
repository,
start,
end,
getAuthParams: () => ({
SCM_TOKEN: '<your_github_token>',
}),
};
const jiraConfig: FetchStoryDataIntegration = {
source: 'jira',
getAuthParams: () => ({
PROJECT_MGMT_BASE_URL: '<your_jira_base_url>',
PROJECT_MGMT_USERNAME: '<your_jira_username_or_email>',
PROJECT_MGMT_TOKEN: '<your_jira_api_token>',
}),
};
const diff = await releaseNotes.generate(githubConfig, jiraConfig);
const output = releaseNotes.format(diff, 'md', {
name: `${repository} v'1.0.0'`,
repositoryOwner: 'invitation-homes',
repository,
});
return output;
}
Project Folder Structure
src
|-- index.ts
|-- types.ts
|-- format
| ├-- index.ts
| ├-- utils.ts
| └-- types.ts
|-- generate
| ├-- index.ts
| └-- utils.ts
|-- integrations
| ├-- index.ts
| ├-- pmt
| | └-- jira.ts
| └-- scm
| └-- github.ts
/src/index.ts
- main entry point, responsible for exporting consumable code for users/src/types.ts
- common TypeScript types that are used across the library/src/generate/index.ts
- main function for generating data for release notes, utils.ts
contains helper functions/src/format/index.ts
- main function for formatting output, utils.ts
contains helper functions/src/integrations/index.ts
- exports an object containing configured integrations
Contributors: Adding a Configured Integration
- Locate the folder
/src/integrations
- Within that folder:
- If adding a source control integration, locate the
./scm
folder - If adding a project management tool integration, locate the
./pmt
folder
- Add a new file with the name of the tool as the filename.
- Implement the new integration, following the implementations of
/src/integrations/scm/github.ts
for SCM and /src/integrations/pmt/jira.ts
for project management tools - In
/src/integrations/index.ts
, import the new integration and export it, following the pattern there. - Add a test (or multiple tests) in
/src/__tests__/index.test.ts
, to validate that it works as expected. Feel free to use the existing tests as a template.
Releases
Releases of this package are automatically published via GitHub actions to the GitHub Packages repository.