Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 331d7d0

Browse files
xiphuxtpruvot
authored andcommittedJun 23, 2014
Add option to filter commits from feeds using a pattern
1 parent f3b3239 commit 331d7d0

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed
 

‎config/gitphp.conf.php.example

+11
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,17 @@ $gitphp_conf['abbreviateurl'] = false;
199199
*/
200200
$gitphp_conf['cleanurl'] = false;
201201

202+
/*
203+
* feedfilter
204+
* Sets a regular expression to use to filter commits out
205+
* of the project atom/rss feed. Commits that have a
206+
* commit message matching this pattern will be excluded.
207+
* For example, '/GIT_SILENT/' will exclude any commit
208+
* with the string GIT_SILENT in the commit message.
209+
*/
210+
//$gitphp_conf['feedfilter'] = '/GIT_SILENT/';
211+
212+
202213
/*********************************************************
203214
* Executable/filesystem options
204215
* Important to check if you're running windows

‎include/controller/Controller_Feed.class.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,9 @@ protected function LoadHeaders()
100100
protected function LoadData()
101101
{
102102
$log = new GitPHP_GitLog($this->GetProject(), $this->GetProject()->GetHeadCommit(), self::MAX_FEED_ITEMS);
103-
104-
//todo: backport..
105-
//if ($this->config->HasKey('feedfilter')) {
106-
// $log->FilterCommits($this->config->GetValue('feedfilter'));
107-
103+
if ($this->config->HasKey('feedfilter')) {
104+
$log->FilterCommits($this->config->GetValue('feedfilter'));
105+
}
108106
// Don't show commits older than 48 hours, but show a minimum of 20 entries
109107
$log->FilterOldCommits(48*60*60, 20);
110108

‎include/git/GitLog.class.php

+32
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,36 @@ public function FilterOldCommits($age, $mini = 0)
164164
}
165165

166166
}
167+
168+
/**
169+
* Filters out commits matching a certain pattern
170+
*
171+
* @param string $pattern pattern
172+
*/
173+
public function FilterCommits($pattern)
174+
{
175+
if (empty($pattern))
176+
return;
177+
178+
if (!$this->dataLoaded) {
179+
$this->LoadData();
180+
}
181+
182+
$filtered = false;
183+
foreach ($this->hashList as $i => $hash) {
184+
$commit = $this->project->GetCommit($hash);
185+
$comment = $commit->GetComment();
186+
foreach ($comment as $commentline) {
187+
if (preg_match($pattern, $commentline)) {
188+
unset($this->hashList[$i]);
189+
$filtered = true;
190+
break;
191+
}
192+
}
193+
}
194+
195+
if ($filtered) {
196+
$this->hashList = array_values($this->hashList);
197+
}
198+
}
167199
}

0 commit comments

Comments
 (0)
Please sign in to comment.