Skip to content

Commit

Permalink
Support specifying git revision on import resources
Browse files Browse the repository at this point in the history
Add an optional input for git revision on the import resources page.
If blank the PipelineResource will automatically detect the default
branch.

Remove helper text below inputs and move content to TooltipIcon on
the label instead for a cleaner UI.
  • Loading branch information
AlanGreene authored and tekton-robot committed Mar 11, 2021
1 parent b285eaf commit 75c65b3
Show file tree
Hide file tree
Showing 15 changed files with 333 additions and 63 deletions.
13 changes: 8 additions & 5 deletions src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export function importResources({
namespace,
path,
repositoryURL,
revision,
serviceAccount
}) {
const taskSpec = {
Expand Down Expand Up @@ -184,11 +185,13 @@ export function importResources({
name: 'url',
value: repositoryURL
},
{
name: 'revision',
value: 'master'
}
]
revision
? {
name: 'revision',
value: revision
}
: null
].filter(Boolean)
};

const pipelineRunSpec = {
Expand Down
161 changes: 157 additions & 4 deletions src/api/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,173 @@ it('importResources', () => {
const mockDateNow = jest
.spyOn(Date, 'now')
.mockImplementation(() => 'fake-timestamp');
const repositoryURL = 'https://github.com/test/testing';
const path = 'fake-directory';
const importerNamespace = 'fake-importer-namespace';
const method = 'apply';
const namespace = 'fake-namespace';
const path = 'fake-directory';
const repositoryURL = 'https://github.com/test/testing';
const serviceAccount = 'fake-serviceAccount';

const payload = {
importerNamespace,
method,
namespace,
path,
repositoryURL,
serviceAccount
};
const data = {
apiVersion: 'tekton.dev/v1beta1',
kind: 'PipelineRun',
metadata: {
name: `import-resources-${Date.now()}`,
labels: {
app: 'tekton-app',
[labels.DASHBOARD_IMPORT]: 'true'
}
},
spec: {
params: [
{
name: 'path',
value: 'fake-directory'
},
{
name: 'target-namespace',
value: 'fake-namespace'
}
],
pipelineSpec: {
params: [
{
default: '.',
description: 'The path from which resources are to be imported',
name: 'path',
type: 'string'
},
{
default: 'tekton-pipelines',
description:
'The namespace in which to create the resources being imported',
name: 'target-namespace',
type: 'string'
}
],
resources: [
{
name: 'git-source',
type: 'git'
}
],
tasks: [
{
name: 'import-resources',
params: [
{
name: 'path',
value: '$(params.path)'
},
{
name: 'target-namespace',
value: '$(params.target-namespace)'
}
],
resources: {
inputs: [
{
name: 'git-source',
resource: 'git-source'
}
]
},
taskSpec: {
params: [
{
default: '.',
description:
'The path from which resources are to be imported',
name: 'path',
type: 'string'
},
{
default: 'tekton-pipelines',
description:
'The namespace in which to create the resources being imported',
name: 'target-namespace',
type: 'string'
}
],
resources: {
inputs: [
{
name: 'git-source',
type: 'git'
}
]
},
steps: [
{
args: [
method,
'-f',
'$(resources.inputs.git-source.path)/$(params.path)',
'-n',
'$(params.target-namespace)'
],
command: ['kubectl'],
image: 'lachlanevenson/k8s-kubectl:latest',
name: 'import'
}
]
}
}
]
},
resources: [
{
name: 'git-source',
resourceSpec: {
params: [
{
name: 'url',
value: 'https://github.com/test/testing'
}
],
type: 'git'
}
}
],
serviceAccountName: serviceAccount
}
};

fetchMock.post('*', { body: data, status: 201 });
return API.importResources(payload).then(response => {
expect(response).toEqual(data);
expect(JSON.parse(fetchMock.lastOptions().body)).toMatchObject(data);
fetchMock.restore();
mockDateNow.mockRestore();
});
});

it('importResources with revision and no serviceAccount', () => {
const mockDateNow = jest
.spyOn(Date, 'now')
.mockImplementation(() => 'fake-timestamp');
const importerNamespace = 'fake-importer-namespace';
const method = 'apply';
const namespace = 'fake-namespace';
const path = 'fake-directory';
const repositoryURL = 'https://github.com/test/testing';
const revision = 'some_git_revision';

const payload = {
importerNamespace,
method,
namespace,
path,
repositoryURL,
serviceAccount
revision
};
const data = {
apiVersion: 'tekton.dev/v1beta1',
Expand Down Expand Up @@ -232,7 +385,7 @@ it('importResources', () => {
},
{
name: 'revision',
value: 'master'
value: revision
}
],
type: 'git'
Expand Down
Loading

0 comments on commit 75c65b3

Please sign in to comment.