Add event timestamp to deployments webhooks

What does this MR do?

See #264393 (closed)

We want to allow users to understand when deployment status transition happened, so this MR captures Time.current and passes it to json payload.

Original implementation is taken from #264393 (comment 477948829)

The alternative is to add created_at to deployment json, and deployable which has started_at/finished_at.

Some arguments against this approach:

  • It's hard to know which attribute to track if the attribute in interest is changed per deployment status. e.g. When the hook receiver should look at deployment.deployable.started_at and when it should look at deployment.finished_at
  • deployable has a lot of attributes and associations, we would want to carefully look at what can be exposed in cheap operation.
  • deployable doesn't exist for deployments created via API i.e. external CD system integration. Hence this approach works for internal CD only.

from this comment

Screenshots (strongly suggested)

{"object_kind":"deployment","status":"success","status_changed_at":"2021-04-28 21:50:00 +0200","deployable_id":857,"deployable_url":"http://10.126.0.2:3000/root/deployment-webhooks-2/-/jobs/857","environment":"staging","project":{"id":37,"name":"deployment-webhooks-2","description":"","web_url":"http://10.126.0.2:3000/root/deployment-webhooks-2","avatar_url":null,"git_ssh_url":"ssh://vlad@10.126.0.2:2222/root/deployment-webhooks-2.git","git_http_url":"http://10.126.0.2:3000/root/deployment-webhooks-2.git","namespace":"Administrator","visibility_level":0,"path_with_namespace":"root/deployment-webhooks-2","default_branch":"master","ci_config_path":null,"homepage":"http://10.126.0.2:3000/root/deployment-webhooks-2","url":"ssh://vlad@10.126.0.2:2222/root/deployment-webhooks-2.git","ssh_url":"ssh://vlad@10.126.0.2:2222/root/deployment-webhooks-2.git","http_url":"http://10.126.0.2:3000/root/deployment-webhooks-2.git"},"short_sha":"5eb17436","user":{"id":1,"name":"Administrator","username":"root","avatar_url":"https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon","email":"admin@example.com"},"user_url":"http://10.126.0.2:3000/root","commit_url":"http://10.126.0.2:3000/root/deployment-webhooks-2/-/commit/5eb1743636f3d1b201ca097d24d69d9b2471db6d","commit_title":"Update .gitlab-ci.yml"}

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Related to #264393 (closed)

Edited by Etienne Baqué

Merge request reports

Loading
Loading