Skip to content

Commit

Permalink
fix(annotator-action): fix generation annotation backstage.io/created…
Browse files Browse the repository at this point in the history
…At (#2114)

Signed-off-by: Oleksandr Andriienko <oandriie@redhat.com>
  • Loading branch information
AndrienkoAleksandr authored Sep 6, 2024
1 parent de81c0f commit 62587be
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ describe('catalog annotator', () => {
'catalog:timestamping',
'Creates a new `catalog:timestamping` Scaffolder action to annotate scaffolded entities with creation timestamp.',
'some logger info msg',
{ annotations: { 'backstage.io/createdAt': getCurrentTimestamp() } },
() => {
return {
annotations: { 'backstage.io/createdAt': getCurrentTimestamp() },
};
},
);

const logger = getVoidLogger();
Expand Down Expand Up @@ -67,7 +71,9 @@ describe('catalog annotator', () => {
'catalog:test-annotate',
'Creates a new `catalog:test-annotate` Scaffolder action to annotate catalog-info.yaml with labels and annotations.',
'',
{},
() => {
return {};
},
);

const logger = getVoidLogger();
Expand Down Expand Up @@ -126,7 +132,9 @@ describe('catalog annotator', () => {
'catalog:test-annotate-obj',
'Creates a new `catalog:test-annotate-obj` Scaffolder action to annotate any object yaml with labels and annotations.',
'some logger info message',
{},
() => {
return {};
},
);

const logger = getVoidLogger();
Expand Down Expand Up @@ -199,8 +207,8 @@ describe('catalog annotator', () => {
'catalog:entityRef',
'Some description',
'some logger info msg',
{
spec: { scaffoldedFrom: 'testt-ref' },
() => {
return { spec: { scaffoldedFrom: 'testt-ref' } };
},
);

Expand Down Expand Up @@ -245,8 +253,12 @@ describe('catalog annotator', () => {
'catalog:entityRef',
'Some description',
'some logger info msg',
{
spec: { scaffoldedFrom: { readFromContext: 'templateInfo.entityRef' } },
() => {
return {
spec: {
scaffoldedFrom: { readFromContext: 'templateInfo.entityRef' },
},
};
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const createAnnotatorAction = (
actionId: string = 'catalog:annotate',
actionDescription?: string,
loggerInfoMsg?: string,
annotateEntityObject?: {
annotateEntityObjectProvider?: () => {
annotations?: { [key: string]: string };
labels?: { [key: string]: string };
spec?: { [key: string]: Value };
Expand Down Expand Up @@ -86,6 +86,7 @@ export const createAnnotatorAction = (
},
},
async handler(ctx) {
const annotateEntityObject = annotateEntityObjectProvider?.();
let objToAnnotate: { [key: string]: any };

if (ctx.input?.objectYaml) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ export const createScaffoldedFromAction = () => {
'catalog:scaffolded-from',
'Creates a new `catalog:scaffolded-from` scaffolder action to update a catalog-info.yaml with the entityRef of the template that created it.',
'Annotating catalog-info.yaml with template entityRef',
{
spec: {
scaffoldedFrom: { readFromContext: 'templateInfo.entityRef' },
},
() => {
return {
spec: {
scaffoldedFrom: { readFromContext: 'templateInfo.entityRef' },
},
};
},
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export const createTimestampAction = () => {
'catalog:timestamping',
'Creates a new `catalog:timestamping` Scaffolder action to annotate scaffolded entities with creation timestamp.',
'Annotating catalog-info.yaml with current timestamp',
{ annotations: { 'backstage.io/createdAt': getCurrentTimestamp() } },
() => {
return {
annotations: { 'backstage.io/createdAt': getCurrentTimestamp() },
};
},
);
};

0 comments on commit 62587be

Please sign in to comment.