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
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
|
|
const baseURL = 'https://api.github.com/repos/grafana/grafana';
|
|
|
|
// Encapsulates the creation of a client for the Github API
|
|
//
|
|
// Two key things:
|
|
// 1. You can specify whenever you want the credentials to be required or not when imported.
|
|
// 2. If the the credentials are available as part of the environment, even if
|
|
// they're not required - the library will use them. This allows us to overcome
|
|
// any API rate limiting imposed without authentication.
|
|
|
|
class GithubClient {
|
|
client: AxiosInstance;
|
|
|
|
constructor(required = false) {
|
|
const username = process.env.GITHUB_USERNAME;
|
|
const token = process.env.GITHUB_ACCESS_TOKEN;
|
|
|
|
const clientConfig: AxiosRequestConfig = {
|
|
baseURL: baseURL,
|
|
timeout: 10000,
|
|
};
|
|
|
|
if (required && !username && !token) {
|
|
throw new Error('operation needs a GITHUB_USERNAME and GITHUB_ACCESS_TOKEN environment variables');
|
|
}
|
|
|
|
if (username && token) {
|
|
clientConfig.auth = { username: username, password: token };
|
|
}
|
|
|
|
this.client = this.createClient(clientConfig);
|
|
}
|
|
|
|
private createClient(clientConfig: AxiosRequestConfig) {
|
|
return axios.create(clientConfig);
|
|
}
|
|
}
|
|
|
|
export default GithubClient;
|