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

Helper function datetime does not match documentation #106

Closed
andreipoe opened this issue Mar 31, 2020 · 4 comments
Closed

Helper function datetime does not match documentation #106

andreipoe opened this issue Mar 31, 2020 · 4 comments

Comments

@andreipoe
Copy link

The documentation page lists datetime as a helper with a single argument, e.g. {{datetime build.started}}, but the function expects 3 arguments:

Evaluation error: Helper 'datetime' called with wrong number of arguments, needed 3 but got 1

Looking at the source code in drone/drone-template-lib:template/helpers.go#L62, it looks like datetime should be called as, for example, {{ datetime build.started "15:04" "" }}. But build.started is an integer and datetime expects a float, resulting in the following error when called as previously exemplified:

Evaluation error: Helper datetime called with argument 0 with type int64 but it should be float64

It doesn't currently seem possible to pass a float value to datetime, so either a helper should be added to allow create converting integers to floats, or the datetime function should allow an integer to be passed in directly.

@tboerger
Copy link
Contributor

In the meantime you could do a typecast, soon I will build a breaking change version which will include sane template helpers based on https://github.com/drone/funcmap, as this really kills all custom template strings this will be a new tagged release with a major version change.

@andreipoe
Copy link
Author

Thanks. That sounds good.

How do you currently do typecasts in templates?

@waterdrop01
Copy link

waterdrop01 commented Jul 6, 2021

Hi @tboerger

Same issue than @andreipoe

Screenshot from 2021-07-06 21-30-40

And here is my .drone.yml

- name: slack
    image: plugins/slack
    settings:
      webhook:
        from_secret: slack-drone-webhook
      channel: alert-drone
      link_names: true
      template: >
        {{#success build.status}}✅{{else}}🐞{{/success}} Build #{{build.number}} of {{repo.name}}@{{build.tag}}

        📝 `{{commit.message}}`
        🙇 {{commit.author}}

        🕐 {{datetime build.started "02.01.2006 15:04" "Europe/Berlin"}}

        🌐 {{build.link}}

Any idea how to cast int64 to float64 in the template?

Thanks!

@ErvalhouS
Copy link

Similar issue to #123 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants