[go: nahoru, domu]

Skip to content
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

Add support for setting user labels on scheduled functions #3408

Merged
merged 4 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/deploy/functions/discovery/jsexports/parseTriggers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ export function addResourcesToBackend(
cloudFunction.trigger.eventFilters.resource = `${cloudFunction.trigger.eventFilters.resource}/${id}`;
}

cloudFunction.labels = { "deployment-scheduled": "true" };
cloudFunction.labels = Object.assign(cloudFunction.labels, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: now that we have object destructuring I personally find it cleaner to use that syntax:

cloudfunctions.labels = {
   ...cloudfunctions.lables,
   "deployment-scheduled": true,
}

Or at least I would if we wanted to create a copy of the dictionary. In this case, your code is equivalent to:

cloudFunction.labels["deployment-scheduled"] = true;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer that too, so I'll switch this over. As is, this is not quite equivalent to cloudFunction.labels["deployment-scheduled"], because labels is optional & can be undefined. Object.assign safely handles that case, wheres the above does not.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

> obj = {}
{}
> obj.labels = Object.assign(obj.lables, {"foo": "bar"});
Uncaught TypeError: Cannot convert undefined or null to object
    at Function.assign (<anonymous>)

Object splat supports undefined but Object.assign does not.

"deployment-scheduled": "true",
});
}

want.cloudFunctions.push(cloudFunction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ describe("addResourcesToBackend", () => {
vpcConnector: "projects/project/locations/region/connectors/connector",
ingressSettings: "ALLOW_ALL",
timeout: "60s",
labels: {
test: "testing",
},
};

const result = backend.empty();
Expand All @@ -146,6 +149,9 @@ describe("addResourcesToBackend", () => {
vpcConnector: "projects/project/locations/region/connectors/connector",
ingressSettings: "ALLOW_ALL",
timeout: "60s",
labels: {
test: "testing",
},
},
],
};
Expand Down Expand Up @@ -260,6 +266,9 @@ describe("addResourcesToBackend", () => {
httpsTrigger: {},
regions: ["us-central1", "europe-west1"],
schedule,
labels: {
test: "testing",
},
};

const result = backend.empty();
Expand All @@ -277,6 +286,7 @@ describe("addResourcesToBackend", () => {
},
labels: {
"deployment-scheduled": "true",
test: "testing",
},
region: "us-central1",
};
Expand All @@ -288,6 +298,7 @@ describe("addResourcesToBackend", () => {
},
labels: {
"deployment-scheduled": "true",
test: "testing",
},
};
const expected: backend.Backend = {
Expand Down