-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(pipelines): ✨ Config allowed pipeline branches #500
base: next
Are you sure you want to change the base?
Changes from all commits
60a5c7b
d36fccc
18ed453
15965bb
0e9e0ac
43109ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"$schema": "node_modules/lerna/schemas/lerna-schema.json", | ||
"npmClient": "yarn", | ||
"version": "6.6.0-alpha.0" | ||
"version": "6.6.0" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,10 @@ import { | |
OAuthApi, | ||
} from '@backstage/core-plugin-api'; | ||
import { PeopleCardEntityData } from '../components/types'; | ||
import { parseCodeOwners } from '../components/utils'; | ||
import { | ||
convertWildcardFilterArrayToFilterFunction, | ||
parseCodeOwners, | ||
} from '../components/utils'; | ||
import { | ||
ContributorsSummary, | ||
GitlabCIApi, | ||
|
@@ -146,21 +149,54 @@ export class GitlabCIClient implements GitlabCIApi { | |
} | ||
|
||
async getPipelineSummary( | ||
projectID?: string | number | ||
projectID?: string | number, | ||
refList?: string[] | ||
): Promise<PipelineSchema[] | undefined> { | ||
const [pipelineObjects, projectObj] = await Promise.all([ | ||
this.callApi<PipelineSchema[]>( | ||
if (!refList || refList.length === 0) { | ||
return this.callApi<PipelineSchema[]>( | ||
'projects/' + projectID + '/pipelines', | ||
{} | ||
), | ||
this.callApi<Record<string, string>>('projects/' + projectID, {}), | ||
]); | ||
); | ||
} | ||
|
||
const projectObj = await this.callApi<Record<string, string>>( | ||
'projects/' + projectID, | ||
{} | ||
); | ||
|
||
const pipelineObjects = []; | ||
let page = 1; | ||
let response; | ||
do { | ||
response = await this.callApi<PipelineSchema[]>( | ||
'projects/' + projectID + '/pipelines', | ||
{ page: page.toString(), per_page: '100' } | ||
); | ||
|
||
if (!response) { | ||
break; | ||
} | ||
|
||
pipelineObjects.push(...response); | ||
page++; | ||
} while (response.length > 0); | ||
|
||
if (pipelineObjects && projectObj) { | ||
pipelineObjects.forEach((element) => { | ||
element.project_name = projectObj.name; | ||
}); | ||
} | ||
return pipelineObjects || undefined; | ||
|
||
const relevantPipelineObjects = refList | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doing this can reduce the number of pipelines you get: ExampleHaving this annotation:
if in your last 50 pipelines, 49 are in branches different from main and develop you will get only one pipeline in your card. Then you can make a request for each branch ex. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @antoniomuso, good catch haven't forgotten about this - just swamped with other work. Hoping to pick this back up in early aug :) |
||
? pipelineObjects?.filter((pipeline) => | ||
convertWildcardFilterArrayToFilterFunction( | ||
pipeline.ref, | ||
refList | ||
) | ||
) | ||
: pipelineObjects; | ||
|
||
return relevantPipelineObjects ?? undefined; | ||
} | ||
|
||
async getIssuesSummary( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { convertWildcardFilterArrayToFilterFunction } from './utils'; | ||
|
||
describe('convertWildcardFilterArrayToFilterFunction', () => { | ||
it('should return true if input matches any of the validInputs', () => { | ||
const input = 'foobar'; | ||
const validInputs = ['foo*', 'bar', 'baz']; | ||
const result = convertWildcardFilterArrayToFilterFunction( | ||
input, | ||
validInputs | ||
); | ||
expect(result).toBeTruthy(); | ||
}); | ||
|
||
it('should return false if input does not match any of the validInputs', () => { | ||
const input = 'foobar'; | ||
const validInputs = ['baz', 'qux']; | ||
const result = convertWildcardFilterArrayToFilterFunction( | ||
input, | ||
validInputs | ||
); | ||
expect(result).toBeFalsy(); | ||
}); | ||
|
||
it('should account for multiple wildcards in the validInputs', () => { | ||
const input = 'foobar'; | ||
const validInputs = ['foo*', '*bar', 'baz']; | ||
const result = convertWildcardFilterArrayToFilterFunction( | ||
input, | ||
validInputs | ||
); | ||
expect(result).toBeTruthy(); | ||
}); | ||
|
||
it('should always return true if any of the valid inputs is *', () => { | ||
const input = 'foobar'; | ||
const validInputs = ['*']; | ||
const result = convertWildcardFilterArrayToFilterFunction( | ||
input, | ||
validInputs | ||
); | ||
expect(result).toBeTruthy(); | ||
}); | ||
|
||
it('should account for ** in the validInputs', () => { | ||
const input = 'foobar'; | ||
const validInputs = ['foo**', 'bar', 'baz']; | ||
const result = convertWildcardFilterArrayToFilterFunction( | ||
input, | ||
validInputs | ||
); | ||
expect(result).toBeTruthy(); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You cannot crawl all pipelines because it can be very inefficient. I suggest using branches API, to get all eligible branches and then query the pipelines API with the right branches.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'Branches' API has the qs parameter
search
that is very useful to implement the wildcard.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can do. How do you recommend configuring the plugin so that you can test the backend against a real GitLab instance locally? I've been running
yarn start
which only tests with the mock response with mock queries.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is hard to test with a real GitLab instance; I have to work on it to increase DevEx. I usually test it by integrating it into a pre-configured backstage environment configured with
gitlab.com
and I usually link the library using yarn.