Skip to content

Commit

Permalink
Merge pull request #57 from Jochen-A-Fuerbacher/JENKINS-34802
Browse files Browse the repository at this point in the history
[JENKINS-34802] Exclude history collection for selected user
  • Loading branch information
Jochen-A-Fuerbacher committed May 17, 2016
2 parents 9132060 + 5e608bb commit 6b3343c
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 9 deletions.
Expand Up @@ -110,7 +110,7 @@ private void onRemove() {
private void onChange() {
final JobConfigHistoryStrategy hdao = PluginUtils.getHistoryDao();
for (Node node : Jenkins.getInstance().getNodes()) {
if (isTracked(node) && !hdao.hasDuplicateHistory(node)) {
if (!PluginUtils.isUserExcluded(PluginUtils.getPlugin()) && isTracked(node) && !hdao.hasDuplicateHistory(node)) {
PluginUtils.getHistoryDao().saveNode(node);
return;
}
Expand Down
Expand Up @@ -69,6 +69,8 @@ public class JobConfigHistory extends Plugin {

/** Maximum number of days to keep entries. */
private String maxDaysToKeepEntries;

private String excludedUsers;

/**
* Flag to indicate we should save 'system' level configurations. A 'system' level configuration is defined as one stored
Expand Down Expand Up @@ -129,6 +131,7 @@ public void configure(StaplerRequest req, JSONObject formData)
excludePattern = formData.getString("excludePattern");
saveModuleConfiguration = formData.getBoolean("saveModuleConfiguration");
showBuildBadges = formData.getString("showBuildBadges");
excludedUsers = formData.getString("excludedUsers");
save();
loadRegexpPatterns();
}
Expand Down Expand Up @@ -358,6 +361,14 @@ public File getConfigFile(final File historyDir) {
// TODO: refactor away from 'File'
return FileHistoryDao.getConfigFile(historyDir);
}

/**
*
* @return comma separated list of usernames, whose changes should not get detected.
*/
public String getExcludedUsers(){
return excludedUsers;
}

/**
* Returns true if configuration for this item should be saved, based on the
Expand Down
Expand Up @@ -53,7 +53,6 @@ public void onCreated(Item item) {
LOG.log(FINEST, "In onCreated for {0}", item);
switchHistoryDao(item).createNewItem((item));
LOG.log(FINEST, "onCreated for {0} done.", item);
// new Exception("STACKTRACE for double invocation").printStackTrace();
}

/**
Expand Down
Expand Up @@ -49,7 +49,7 @@ public class JobConfigHistorySaveableListener extends SaveableListener {
public void onChange(final Saveable o, final XmlFile file) {
final JobConfigHistory plugin = getPlugin();
LOG.log(FINEST, "In onChange for {0}", o);
if (plugin.isSaveable(o, file)) {
if (plugin.isSaveable(o, file) && !PluginUtils.isUserExcluded(plugin)) {
final HistoryDao configHistoryListenerHelper = getHistoryDao(plugin);
configHistoryListenerHelper.saveItem(file);
}
Expand Down
27 changes: 22 additions & 5 deletions src/main/java/hudson/plugins/jobConfigHistory/PluginUtils.java
Expand Up @@ -33,6 +33,7 @@
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;

/**
* Helper class.
Expand Down Expand Up @@ -123,11 +124,27 @@ public static JobConfigHistoryStrategy getHistoryDao(final JobConfigHistory plug
maxHistoryEntries = 0;
}
return new FileHistoryDao(
plugin.getConfiguredHistoryRootDir(),
new File(Hudson.getInstance().root.getPath()),
user,
maxHistoryEntries,
!plugin.getSkipDuplicateHistory());
plugin.getConfiguredHistoryRootDir(),
new File(Hudson.getInstance().root.getPath()),
user,
maxHistoryEntries,
!plugin.getSkipDuplicateHistory());
}

public static boolean isUserExcluded(final JobConfigHistory plugin){

final User user = User.current();

if(plugin.getExcludedUsers()!= null){
String excludedUsers = plugin.getExcludedUsers().trim();
String[] segs = excludedUsers.split(Pattern.quote(","));
for(String seg : segs){
if(user != null && user.getId() != null && seg.trim().equals(user.getId())){
return true;
}
}
}
return false;
}

/**
Expand Down
Expand Up @@ -36,6 +36,9 @@
<br />
<f:radio name="showBuildBadges" title="${%Only for administrators}" value="adminUser" checked="${it.getShowBuildBadges() == 'adminUser'}"/>
</f:entry>
<f:entry title="${%Exclude users}" help="/plugin/jobConfigHistory/help/help-excludeUsers.html">
<f:textbox name="excludedUsers" value="${it.excludedUsers}" />
</f:entry>
</f:advanced>
</f:section>
</j:jelly>
4 changes: 4 additions & 0 deletions src/main/webapp/help/help-excludeUsers.html
@@ -0,0 +1,4 @@
Comma separated list of users (userIds), whose changes should not get detected by JobConfigHistory.
It doesn't affect on deletions, creations or renames.

Changes on configurations will then be assigned to the next, not excluded user.
Expand Up @@ -403,7 +403,8 @@ JSONObject createFormData() {
"\"skipDuplicateHistory\": true," +
"\"excludePattern\": \"5\"," +
"\"saveModuleConfiguration\": true," +
"\"showBuildBadges\": \"5\"" +
"\"showBuildBadges\": \"5\"," +
"\"excludedUsers\": \"\"" +
"}");
}
}

0 comments on commit 6b3343c

Please sign in to comment.