- page_title "Triggers"

.row.prepend-top-default.append-bottom-default
  .col-lg-3
    %h4.prepend-top-0
      = page_title
    %p
      Triggers can force a specific branch or tag to rebuild with an API call.
  .col-lg-9
    %h5.prepend-top-0
      Your triggers
    - if @triggers.any?
      .table-responsive
        %table.table
          %thead
            %th Token
            %th Last used
            %th
          = render partial: 'trigger', collection: @triggers, as: :trigger
    - else
      %p.settings-message.text-center.append-bottom-default
        No triggers have been created yet. Add one using the button below.

    = form_for @trigger, url: url_for(controller: 'projects/triggers', action: 'create') do |f|
      = f.submit "Add Trigger", class: 'btn btn-success'

    %h5.prepend-top-default
      Use CURL

    %p.light
      Copy the token above, set your branch or tag name, and that reference will be rebuilt.

    %pre
      :plain
        curl -X POST \
             -F token=TOKEN \
             -F ref=REF_NAME \
             #{builds_trigger_url(@project.id)}
    %h5.prepend-top-default
      Use .gitlab-ci.yml

    %p.light
      In the
      %code .gitlab-ci.yml
      of the dependent project, include the following snippet.
      The project will rebuild at the end of the build.

    %pre
      :plain
        trigger:
          type: deploy
          script:
            - "curl -X POST -F token=TOKEN -F ref=REF_NAME #{builds_trigger_url(@project.id)}"
    %h5.prepend-top-default
      Pass build variables

    %p.light
      Add
      %code variables[VARIABLE]=VALUE
      to an API request. Variable values can be used to distinguish between triggered builds and normal builds.

    %pre.append-bottom-0
      :plain
        curl -X POST \
             -F token=TOKEN \
             -F "ref=REF_NAME" \
             -F "variables[RUN_NIGHTLY_BUILD]=true" \
             #{builds_trigger_url(@project.id)}
