Indefero

Indefero Commit Details


Date:2011-09-24 19:03:35 (13 years 2 months ago)
Author:Thomas Keller
Branch:develop, release-1.3
Commit:b29acd71cb32521c63d9ce94539c586b89d43c68
Parents: dc50e9b3162dccf251d24679ae0301e20e5ac0d0
Message:Add an option to specify a webhook URL for updates in the downloads section and tweak the help texts for the original source web hook a bit. Also remove the superfluous inline help code from the SourceConf form that was actually not used.

This feature was sponsored by Scilab.
Changes:

File differences

src/IDF/Commit.php
297297
298298
299299
300
300
301301
302302
303303
'creation_date' => $this->creation_dtime,
),
'project_id' => $project->id,
'authkey' => $project->getPostCommitHookKey(),
'authkey' => $project->getWebHookKey(),
'url' => $url,
);
$item = new IDF_Queue();
src/IDF/Form/SourceConf.php
4949
5050
5151
52
53
5452
5553
5654
5755
58
5956
6057
6158
'widget' => 'Pluf_Form_Widget_PasswordInput',
));
}
Pluf::loadFunction('Pluf_HTTP_URL_urlForView');
$url = Pluf_HTTP_URL_urlForView('idf_faq').'#webhooks';
$this->fields['webhook_url'] = new Pluf_Form_Field_Url(
array('required' => false,
'label' => __('Webhook URL'),
'initial' => $this->conf->getVal('webhook_url', ''),
'help_text' => sprintf(__('Learn more about the <a href="%s">post-commit web hooks</a>.'), $url),
'widget_attrs' => array('size' => 35),
));
src/IDF/Form/UploadConf.php
6060
6161
6262
63
63
6464
6565
6666
67
68
69
70
71
72
73
74
6775
6876
6977
$this->fields['labels_download_one_max'] = new Pluf_Form_Field_Varchar(
array('required' => false,
'label' => __('Each download may have at most one label with each of these classes'),
'initial' => self::init_one_max,
'initial' => self::init_one_max,
'widget_attrs' => array('size' => 60),
));
$this->conf = $extra['conf'];
$this->fields['upload_webhook_url'] = new Pluf_Form_Field_Url(
array('required' => false,
'label' => __('Webhook URL'),
'initial' => $this->conf->getVal('upload_webhook_url', ''),
'widget_attrs' => array('size' => 60),
));
}
}
src/IDF/Project.php
494494
495495
496496
497
497
498498
499499
500500
501501
502
502
503503
504504
505505
}
/**
* Get the post commit hook key.
* Get the web hook key.
*
* The goal is to get something predictable but from which one
* cannot reverse find the secret key.
*/
public function getPostCommitHookKey()
public function getWebHookKey()
{
return md5($this->id.sha1(Pluf::f('secret_key')).$this->shortname);
}
src/IDF/Views/Project.php
375375
376376
377377
378
379
380
378381
379
382
380383
381384
382385
......
388391
389392
390393
391
394
392395
393396
394397
......
398401
399402
400403
401
404
402405
403406
404407
405408
406409
410
407411
408412
409413
......
598602
599603
600604
601
605
602606
603607
604608
$title = sprintf(__('%s Downloads Configuration'), (string) $prj);
$conf = new IDF_Conf();
$conf->setProject($prj);
$extra = array(
'conf' => $conf,
);
if ($request->method == 'POST') {
$form = new IDF_Form_UploadConf($request->POST);
$form = new IDF_Form_UploadConf($request->POST, $extra);
if ($form->isValid()) {
foreach ($form->cleaned_data as $key=>$val) {
$conf->setVal($key, $val);
}
} else {
$params = array();
$keys = array('labels_download_predefined', 'labels_download_one_max');
$keys = array('labels_download_predefined', 'labels_download_one_max', 'upload_webhook_url');
foreach ($keys as $key) {
$_val = $conf->getVal($key, false);
if ($_val !== false) {
if (count($params) == 0) {
$params = null; //Nothing in the db, so new form.
}
$form = new IDF_Form_UploadConf($params);
$form = new IDF_Form_UploadConf($params, $extra);
}
return Pluf_Shortcuts_RenderToResponse('idf/admin/downloads.html',
array(
'page_title' => $title,
'form' => $form,
'hookkey' => $prj->getWebHookKey(),
),
$request);
}
'repository_size' => $prj->getRepositorySize(),
'page_title' => $title,
'form' => $form,
'hookkey' => $prj->getPostCommitHookKey(),
'hookkey' => $prj->getWebHookKey(),
),
$request);
}
src/IDF/templates/idf/admin/downloads.html
11
2
2
33
44
55
......
1616
1717
1818
19
20
21
22
23
24
25
26
27
1928
2029
2130
......
3140
3241
3342
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
3468
{extends "idf/admin/base.html"}
{block docclass}yui-t1{assign $inDownloads = true}{/block}
{block docclass}yui-t3{assign $inDownloads = true}{/block}
{block body}
<form method="post" action=".">
<table class="form" summary="">
</td>
</tr>
<tr>
<td>{$form.f.upload_webhook_url.labelTag}:<br />
{if $form.f.upload_webhook_url.errors}{$form.f.upload_webhook_url.fieldErrors}{/if}
{$form.f.upload_webhook_url|unsafe}<br>
</td>
</tr>
<tr>
<td>{trans 'Web-Hook authentication key:'} {$hookkey}</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="{trans 'Save Changes'}" name="submit" />
</td>
<p>Optionally, use an equals-sign to document the meaning of each status value.</p>
{/blocktrans}
</div>
<div class="issue-submit-info">
{blocktrans}<p>The webhook URL setting specifies an URL to which a HTTP <strong>PUT</strong>
request is sent after a new download has been added or to which a HTTP <strong>POST</strong>
request is sent after an existing download has been updated.
If this field is empty, notifications are disabled.</p>
<p>Only properly-escaped <strong>HTTP</strong> URLs are supported, for example:</p>
<ul>
<li><code>http://domain.com/upload</code></li>
<li><code>http://domain.com/upload?my%20param</code></li>
</ul>
<p>In addition, the URL may contain the following "%" notation, which
will be replaced with specific project values for each download:</p>
<ul>
<li><code>%p</code> - project name</li>
<li><code>%d</code> - download id</li>
</ul>
<p>For example, updating download 123 of project 'my-project' with
web hook URL <code>http://mydomain.com/%p/%d</code> would send a POST request to
<code>http://mydomain.com/my-project/123</code>.</p>{/blocktrans}</div>
{/block}
src/IDF/templates/idf/admin/source.html
4242
4343
4444
45
4645
4746
4847
49
48
5049
5150
5251
......
6867
6968
7069
71
70
7271
7372
7473
7574
7675
7776
78
79
77
78
8079
8180
8281
8382
8483
8584
86
87
85
86
8887
8988
9089
91
92
90
91
9392
<th>{$form.f.webhook_url.labelTag}:</th>
<td>{if $form.f.webhook_url.errors}{$form.f.webhook_url.fieldErrors}{/if}
{$form.f.webhook_url|unsafe}<br>
</td>
</tr>
<tr>
<th>{trans 'Post-commit authentication key:'}</th>
<th>{trans 'Web-Hook authentication key:'}</th>
<td>{$hookkey}
</td>
</tr>
<br>
<div class="issue-submit-info">
{blocktrans}<p>The webhook URL setting specifies a URL to which a HTTP POST
{blocktrans}<p>The webhook URL setting specifies an URL to which a HTTP POST
request is sent after each repository commit. If this field is empty,
notifications are disabled.</p>
<p>Only properly-escaped <strong>HTTP</strong> URLs are supported, for example:</p>
<ul>
<li>http://domain.com/commit</li>
<li>http://domain.com/commit?my%20param</li>
<li><code>http://domain.com/commit</code></li>
<li><code>http://domain.com/commit?my%20param</code></li>
</ul>
<p>In addition, the URL may contain the following "%" notation, which
will be replaced with specific project values for each commit:</p>
<ul>
<li>%p - project name</li>
<li>%r - revision number</li>
<li><code>%p</code> - project name</li>
<li><code>%r</code> - revision number</li>
</ul>
<p>For example, committing revision 123 to project 'my-project' with
post-commit URL http://mydomain.com/%p/%r would send a request to
http://mydomain.com/my-project/123.</p>{/blocktrans}</div>
post-commit URL <code>http://mydomain.com/%p/%r</code> would send a request to
<code>http://mydomain.com/my-project/123</code>.</p>{/blocktrans}</div>
{/block}

Archive Download the corresponding diff file

Page rendered in 0.10526s using 13 queries.