<%- title t('webhooks.info.title') %>
<%- description "Setting up a webook to update scripts on #{site_name} automatically." %>

<h2><%= t('webhooks.info.title')  %></h2>

<%= it('webhooks.info.intro_html', site_name: site_name, import_link: import_start_path) %>

<% if @webhook_scripts.any? %>
  <p><%= t('webhooks.info.already_syncing_list') %></p>
  <ul>
    <% @webhook_scripts.each do |s| %>
      <li><%= t('webhooks.info.synced_item_html', script_name: link_to(s.name, s), sync_type: t("scripts.sync_type_#{Script.sync_types[s.sync_type]}.name"), sync_url: link_to(s.sync_identifier, s.sync_identifier)) %></li>
    <% end %>
  </ul>
<% end %>

<% unless I18n.locale == :en %>
  <p><%= t('webhooks.info.language_note') %></p>
<% end %>

<h3>GitHub</h3>

<p>The sync URL should be the URL GitHub provides for the "Raw" version of a file. <%= site_name %> will look for the following formats:</p>

<ul>
  <li>https://raw.githubusercontent.com/<b>YourRepoName</b>/<b>YourProjectName</b>/<b>YourBranchName</b>/<b>path/to/script.user.js</b></li>
  <li>https://raw.githubusercontent.com/<b>YourRepoName</b>/<b>YourProjectName</b>/refs/heads/<b>YourBranchName</b>/<b>path/to/script.user.js</b></li>
  <li>https://github.com/<b>YourRepoName</b>/<b>YourProjectName</b>/raw/<b>YourBranchName</b>/<b>path/to/script.user.js</b></li>
  <li>https://github.com/<b>YourRepoName</b>/<b>YourProjectName</b>/raw/refs/heads/<b>YourBranchName</b>/<b>path/to/script.user.js</b></li>
  <li>https://github.com/<b>YourRepoName</b>/<b>YourProjectName</b>/releases/latest/download/<b>script.user.js</b> (only for release events, where <b>script.user.js</b> is added to the release as an asset)</li>
</ul>

<p>To set up the webhook on GitHub, access your GitHub repository and go to Settings, Webhooks, Add webhook, then enter the data below.</p>

<dl>
  <dt>Payload URL</dt>
  <dd><%= @webhook_url %></dd>
  <dt>Content type</dt>
  <dd>application/json</dd>
  <dt>Secret</dt>
  <dd>
    <%= form_tag do |f| %>
      <% if @user.webhook_secret.nil? %>
        <input type="submit" value="Generate">
      <% else %>
        <textarea cols="64" rows="2" readonly><%= @user.webhook_secret %></textarea> <input type="submit" value="Regenerate">
      <% end %>
    <% end %>
  </dd>
  <dt>Which events would you like to trigger this webhook?</dt>
  <dd>
    To update <%= site_name %> on all pushes, choose "Just the push event".<br>
    To update <%= site_name %> only on releases, choose "Let me select individual events", uncheck "Pushes", and check "Releases".<br>
    (In either case, <%= site_name %> will be looking for modified files in these events.)
  </dd>

  <dt>Active</dt>
  <dd>(Checked)</dd>
</dl>

<h3>Bitbucket</h3>

<p>The sync URL you supply to <%= site_name %> must be one of the following formats:</p>

<ul>
  <li>https://bitbucket.org/<b>YourRepoName</b>/<b>YourProjectName</b>/raw/<b>master</b>/<b>path/to/script.user.js</b></li>
</ul>

<p>To set up the webhook on Bitbucket, access your Bitbucket repository and go to Repository Settings, Webhooks, Add webhook, then enter the data below.</p>

<dl>
  <dt>Title</dt>
  <dd><%= site_name %></dd>
  <dt>URL</dt>
  <dd>
    <%= form_tag do |f| %>
      <% if @user.webhook_secret.nil? %>
        <input type="submit" value="Generate">
      <% else %>
        <textarea cols="64" rows="2" readonly><%= @webhook_url_with_secret %></textarea> <input type="submit" value="Regenerate">
      <% end %>
    <% end %>
  </dd>
  <dt>Active</dt>
  <dd>(Checked)</dd>
  <dt>Skip certificate verification</dt>
  <dd>(Unchecked)</dd>
  <dt>Enable request history collection</dt>
  <dd>(Unchecked)</dd>
  <dt>Triggers</dt>
  <dd>Repository push</dd>
</dl>

<h3>GitLab</h3>

<p>The sync URL you supply to <%= site_name %> must be one of the following formats:</p>

<ul>
  <li>https://gitlab.com/<b>YourRepoName</b>/<b>YourProjectName</b>/raw/<b>master</b>/<b>path/to/script.user.js</b></li>
  <li>https://gitlab.com/<b>YourRepoName</b>/<b>YourProjectName</b>/-/raw/<b>master</b>/<b>path/to/script.user.js</b></li>
  <li>https://gitlab.com/api/v4/projects/<b>YourNumericalProjectID</b>/repository/files/<b>path/to/script.user.js</b>/raw?ref=<b>master</b> (can include further parameters - this is mostly useful for private repos)</li>
</ul>

<p>To set up the webhook on GitLab, access your GitLab repository and go to <b>Settings</b> → <b>Webhooks</b>, then enter the data below:</p>

<dl>
  <dt>URL</dt>
  <dd><%= @webhook_url %></dd>
  <dt>Secret Token</dt>
  <dd>
    <%= form_tag do |f| %>
      <% if @user.webhook_secret.nil? %>
        <input type="submit" value="Generate">
      <% else %>
        <textarea cols="64" rows="2" readonly><%= @user.webhook_secret %></textarea> <input type="submit" value="Regenerate">
      <% end %>
    <% end %>
  </dd>
  <dt>Trigger</dt>
  <dd>
    To update <%= site_name %> on all pushes, choose "Push events".<br>
    To update <%= site_name %> only on releases, choose "Releases events".</dd>
  </dd>
  <dt>Enable SSL Verification</dt>
  <dd>(Checked)</dd>
</dl>
