mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 14:32:12 +08:00

* Don't display changelog category title when no items The output of the changelog is meant to be copy/pasted with ease. When a changelog category does not contain items is better to not display title at all thus avoiding having the manually modify the output as we include it in the steps of the process. * Introduce a CLI task to close milestones whilst doing a Grafana release As part of a Grafana release, we need to eventually close the GitHub milestone to indicate is done and remove all the cherry-pick labels from issues/prs within the milestone to avoid our cherry-pick CLI command to pick them up on the next release. * Abstract the GitHub client into a module * Introduce `GitHubClient` to all CLI tasks
67 lines
1.9 KiB
TypeScript
67 lines
1.9 KiB
TypeScript
import GithubClient from './githubClient';
|
|
|
|
const fakeClient = jest.fn();
|
|
|
|
beforeEach(() => {
|
|
delete process.env.GITHUB_USERNAME;
|
|
delete process.env.GITHUB_ACCESS_TOKEN;
|
|
});
|
|
|
|
afterEach(() => {
|
|
delete process.env.GITHUB_USERNAME;
|
|
delete process.env.GITHUB_ACCESS_TOKEN;
|
|
});
|
|
|
|
describe('GithubClient', () => {
|
|
it('should initialise a GithubClient', () => {
|
|
const github = new GithubClient();
|
|
expect(github).toBeInstanceOf(GithubClient);
|
|
});
|
|
|
|
describe('#client', () => {
|
|
it('it should contain a client', () => {
|
|
const spy = jest.spyOn(GithubClient.prototype, 'createClient').mockImplementation(() => fakeClient);
|
|
|
|
const github = new GithubClient();
|
|
const client = github.client;
|
|
|
|
expect(spy).toHaveBeenCalledWith({
|
|
baseURL: 'https://api.github.com/repos/grafana/grafana',
|
|
timeout: 10000,
|
|
});
|
|
expect(client).toEqual(fakeClient);
|
|
});
|
|
|
|
describe('when the credentials are required', () => {
|
|
it('should create the client when the credentials are defined', () => {
|
|
const username = 'grafana';
|
|
const token = 'averysecureaccesstoken';
|
|
|
|
process.env.GITHUB_USERNAME = username;
|
|
process.env.GITHUB_ACCESS_TOKEN = token;
|
|
|
|
const spy = jest.spyOn(GithubClient.prototype, 'createClient').mockImplementation(() => fakeClient);
|
|
|
|
const github = new GithubClient(true);
|
|
const client = github.client;
|
|
|
|
expect(spy).toHaveBeenCalledWith({
|
|
baseURL: 'https://api.github.com/repos/grafana/grafana',
|
|
timeout: 10000,
|
|
auth: { username, password: token },
|
|
});
|
|
|
|
expect(client).toEqual(fakeClient);
|
|
});
|
|
|
|
describe('when the credentials are not defined', () => {
|
|
it('should throw an error', () => {
|
|
expect(() => {
|
|
new GithubClient(true);
|
|
}).toThrow(/operation needs a GITHUB_USERNAME and GITHUB_ACCESS_TOKEN environment variables/);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|