Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
2cdd73cf
Unverified
Commit
2cdd73cf
authored
Sep 26, 2019
by
Ivana Huckova
Committed by
GitHub
Sep 26, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Release: Create cherrypick task work for enterprise repo (#19424)
parent
8f01e9c0
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
58 additions
and
11 deletions
+58
-11
packages/grafana-toolkit/src/cli/index.ts
+2
-1
packages/grafana-toolkit/src/cli/tasks/cherrypick.ts
+5
-3
packages/grafana-toolkit/src/cli/tasks/closeMilestone.ts
+1
-1
packages/grafana-toolkit/src/cli/utils/githubClient.test.ts
+41
-3
packages/grafana-toolkit/src/cli/utils/githubClient.ts
+9
-3
No files found.
packages/grafana-toolkit/src/cli/index.ts
View file @
2cdd73cf
...
@@ -68,9 +68,10 @@ export const run = (includeInternalScripts = false) => {
...
@@ -68,9 +68,10 @@ export const run = (includeInternalScripts = false) => {
program
program
.
command
(
'cherrypick'
)
.
command
(
'cherrypick'
)
.
option
(
'-e, --enterprise'
,
'Run task for grafana-enterprise'
)
.
description
(
'Helps find commits to cherry pick'
)
.
description
(
'Helps find commits to cherry pick'
)
.
action
(
async
cmd
=>
{
.
action
(
async
cmd
=>
{
await
execTask
(
cherryPickTask
)({});
await
execTask
(
cherryPickTask
)({
enterprise
:
!!
cmd
.
enterprise
});
});
});
program
program
...
...
packages/grafana-toolkit/src/cli/tasks/cherrypick.ts
View file @
2cdd73cf
import
{
Task
,
TaskRunner
}
from
'./task'
;
import
{
Task
,
TaskRunner
}
from
'./task'
;
import
GithubClient
from
'../utils/githubClient'
;
import
GithubClient
from
'../utils/githubClient'
;
interface
CherryPickOptions
{}
interface
CherryPickOptions
{
enterprise
:
boolean
;
}
const
cherryPickRunner
:
TaskRunner
<
CherryPickOptions
>
=
async
()
=>
{
const
cherryPickRunner
:
TaskRunner
<
CherryPickOptions
>
=
async
(
{
enterprise
}
)
=>
{
const
githubClient
=
new
GithubClient
();
const
githubClient
=
new
GithubClient
(
{
enterprise
}
);
const
client
=
githubClient
.
client
;
const
client
=
githubClient
.
client
;
const
res
=
await
client
.
get
(
'/issues'
,
{
const
res
=
await
client
.
get
(
'/issues'
,
{
...
...
packages/grafana-toolkit/src/cli/tasks/closeMilestone.ts
View file @
2cdd73cf
...
@@ -6,7 +6,7 @@ interface CloseMilestoneOptions {
...
@@ -6,7 +6,7 @@ interface CloseMilestoneOptions {
}
}
const
closeMilestoneTaskRunner
:
TaskRunner
<
CloseMilestoneOptions
>
=
async
({
milestone
})
=>
{
const
closeMilestoneTaskRunner
:
TaskRunner
<
CloseMilestoneOptions
>
=
async
({
milestone
})
=>
{
const
githubClient
=
new
GithubClient
(
true
);
const
githubClient
=
new
GithubClient
(
{
required
:
true
}
);
const
cherryPickLabel
=
'cherry-pick needed'
;
const
cherryPickLabel
=
'cherry-pick needed'
;
const
client
=
githubClient
.
client
;
const
client
=
githubClient
.
client
;
...
...
packages/grafana-toolkit/src/cli/utils/githubClient.test.ts
View file @
2cdd73cf
...
@@ -15,11 +15,13 @@ afterEach(() => {
...
@@ -15,11 +15,13 @@ afterEach(() => {
describe
(
'GithubClient'
,
()
=>
{
describe
(
'GithubClient'
,
()
=>
{
it
(
'should initialise a GithubClient'
,
()
=>
{
it
(
'should initialise a GithubClient'
,
()
=>
{
const
github
=
new
GithubClient
();
const
github
=
new
GithubClient
();
const
githubEnterprise
=
new
GithubClient
({
enterprise
:
true
});
expect
(
github
).
toBeInstanceOf
(
GithubClient
);
expect
(
github
).
toBeInstanceOf
(
GithubClient
);
expect
(
githubEnterprise
).
toBeInstanceOf
(
GithubClient
);
});
});
describe
(
'#client'
,
()
=>
{
describe
(
'#client'
,
()
=>
{
it
(
'it should contain a client'
,
()
=>
{
it
(
'it should contain a
grafana
client'
,
()
=>
{
// @ts-ignore
// @ts-ignore
const
spy
=
jest
.
spyOn
(
GithubClient
.
prototype
,
'createClient'
).
mockImplementation
(()
=>
fakeClient
);
const
spy
=
jest
.
spyOn
(
GithubClient
.
prototype
,
'createClient'
).
mockImplementation
(()
=>
fakeClient
);
...
@@ -33,6 +35,20 @@ describe('GithubClient', () => {
...
@@ -33,6 +35,20 @@ describe('GithubClient', () => {
expect
(
client
).
toEqual
(
fakeClient
);
expect
(
client
).
toEqual
(
fakeClient
);
});
});
it
(
'it should contain a grafana enterprise client'
,
()
=>
{
// @ts-ignore
const
spy
=
jest
.
spyOn
(
GithubClient
.
prototype
,
'createClient'
).
mockImplementation
(()
=>
fakeClient
);
const
github
=
new
GithubClient
({
enterprise
:
true
});
const
client
=
github
.
client
;
expect
(
spy
).
toHaveBeenCalledWith
({
baseURL
:
'https://api.github.com/repos/grafana/grafana-enterprise'
,
timeout
:
10000
,
});
expect
(
client
).
toEqual
(
fakeClient
);
});
describe
(
'when the credentials are required'
,
()
=>
{
describe
(
'when the credentials are required'
,
()
=>
{
it
(
'should create the client when the credentials are defined'
,
()
=>
{
it
(
'should create the client when the credentials are defined'
,
()
=>
{
const
username
=
'grafana'
;
const
username
=
'grafana'
;
...
@@ -44,7 +60,7 @@ describe('GithubClient', () => {
...
@@ -44,7 +60,7 @@ describe('GithubClient', () => {
// @ts-ignore
// @ts-ignore
const
spy
=
jest
.
spyOn
(
GithubClient
.
prototype
,
'createClient'
).
mockImplementation
(()
=>
fakeClient
);
const
spy
=
jest
.
spyOn
(
GithubClient
.
prototype
,
'createClient'
).
mockImplementation
(()
=>
fakeClient
);
const
github
=
new
GithubClient
(
true
);
const
github
=
new
GithubClient
(
{
required
:
true
}
);
const
client
=
github
.
client
;
const
client
=
github
.
client
;
expect
(
spy
).
toHaveBeenCalledWith
({
expect
(
spy
).
toHaveBeenCalledWith
({
...
@@ -56,11 +72,33 @@ describe('GithubClient', () => {
...
@@ -56,11 +72,33 @@ describe('GithubClient', () => {
expect
(
client
).
toEqual
(
fakeClient
);
expect
(
client
).
toEqual
(
fakeClient
);
});
});
it
(
'should create the enterprise client when the credentials are defined'
,
()
=>
{
const
username
=
'grafana'
;
const
token
=
'averysecureaccesstoken'
;
process
.
env
.
GITHUB_USERNAME
=
username
;
process
.
env
.
GITHUB_ACCESS_TOKEN
=
token
;
// @ts-ignore
const
spy
=
jest
.
spyOn
(
GithubClient
.
prototype
,
'createClient'
).
mockImplementation
(()
=>
fakeClient
);
const
github
=
new
GithubClient
({
required
:
true
,
enterprise
:
true
});
const
client
=
github
.
client
;
expect
(
spy
).
toHaveBeenCalledWith
({
baseURL
:
'https://api.github.com/repos/grafana/grafana-enterprise'
,
timeout
:
10000
,
auth
:
{
username
,
password
:
token
},
});
expect
(
client
).
toEqual
(
fakeClient
);
});
describe
(
'when the credentials are not defined'
,
()
=>
{
describe
(
'when the credentials are not defined'
,
()
=>
{
it
(
'should throw an error'
,
()
=>
{
it
(
'should throw an error'
,
()
=>
{
expect
(()
=>
{
expect
(()
=>
{
// tslint:disable-next-line
// tslint:disable-next-line
new
GithubClient
(
true
);
new
GithubClient
(
{
required
:
true
}
);
}).
toThrow
(
/operation needs a GITHUB_USERNAME and GITHUB_ACCESS_TOKEN environment variables/
);
}).
toThrow
(
/operation needs a GITHUB_USERNAME and GITHUB_ACCESS_TOKEN environment variables/
);
});
});
});
});
...
...
packages/grafana-toolkit/src/cli/utils/githubClient.ts
View file @
2cdd73cf
import
axios
,
{
AxiosInstance
,
AxiosRequestConfig
}
from
'axios'
;
import
axios
,
{
AxiosInstance
,
AxiosRequestConfig
}
from
'axios'
;
const
baseURL
=
'https://api.github.com/repos/grafana/grafana'
;
const
grafanaURL
=
'https://api.github.com/repos/grafana/grafana'
;
const
enterpriseURL
=
'https://api.github.com/repos/grafana/grafana-enterprise'
;
// Encapsulates the creation of a client for the Github API
// Encapsulates the creation of a client for the Github API
//
//
...
@@ -10,15 +11,20 @@ const baseURL = 'https://api.github.com/repos/grafana/grafana';
...
@@ -10,15 +11,20 @@ const baseURL = 'https://api.github.com/repos/grafana/grafana';
// they're not required - the library will use them. This allows us to overcome
// they're not required - the library will use them. This allows us to overcome
// any API rate limiting imposed without authentication.
// any API rate limiting imposed without authentication.
interface
GithubClientProps
{
required
?:
boolean
;
enterprise
?:
boolean
;
}
class
GithubClient
{
class
GithubClient
{
client
:
AxiosInstance
;
client
:
AxiosInstance
;
constructor
(
required
=
false
)
{
constructor
(
{
required
=
false
,
enterprise
=
false
}:
GithubClientProps
=
{}
)
{
const
username
=
process
.
env
.
GITHUB_USERNAME
;
const
username
=
process
.
env
.
GITHUB_USERNAME
;
const
token
=
process
.
env
.
GITHUB_ACCESS_TOKEN
;
const
token
=
process
.
env
.
GITHUB_ACCESS_TOKEN
;
const
clientConfig
:
AxiosRequestConfig
=
{
const
clientConfig
:
AxiosRequestConfig
=
{
baseURL
:
base
URL
,
baseURL
:
enterprise
?
enterpriseURL
:
grafana
URL
,
timeout
:
10000
,
timeout
:
10000
,
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment