Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: poll manifest file #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions src/main/java/hudson/plugins/repo/RepoScm.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public class RepoScm extends SCM implements Serializable {
@CheckForNull private boolean resetFirst;
@CheckForNull private boolean cleanFirst;
@CheckForNull private boolean quiet;
@CheckForNull private boolean pollManifest;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name is misleading, since the manifest is always polled.
maybe pollManifestOnly ?

@CheckForNull private boolean forceSync;
@CheckForNull private boolean trace;
@CheckForNull private boolean showAllChanges;
Expand Down Expand Up @@ -306,6 +307,13 @@ public boolean isShowAllChanges() {
public boolean isQuiet() {
return quiet;
}
/**
* Returns the value of pollManifest.
*/
@Exported
public boolean isPollManifest() {
return pollManifest;
}
/**
* Returns the value of forceSync.
*/
Expand Down Expand Up @@ -462,6 +470,7 @@ public RepoScm(final String manifestRepositoryUrl) {
resetFirst = false;
cleanFirst = false;
quiet = false;
pollManifest = false;
forceSync = false;
trace = false;
showAllChanges = false;
Expand Down Expand Up @@ -634,6 +643,17 @@ public void setQuiet(final boolean quiet) {
this.quiet = quiet;
}

/**
* Set pollManifest.
*
* @param pollManifest
* If this value is true, do "git rev-list HEAD -1 mainifest_file".
*/
@DataBoundSetter
public void setPollManifest(final boolean pollManifest) {
this.pollManifest = pollManifest;
}

/**
* Set trace.
*
Expand Down Expand Up @@ -1125,9 +1145,17 @@ private String getManifestRevision(final Launcher launcher,
throws IOException, InterruptedException {
final ByteArrayOutputStream output = new ByteArrayOutputStream();
final List<String> commands = new ArrayList<String>(6);
commands.add("git");
commands.add("rev-parse");
commands.add("HEAD");
if (pollManifest && manifestFile != null) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is always a manifest file, even if none is specified : it defaults to 'default.xml'

If this poll manifest option is enabled, and the name of manifest is not specified, then it should still check the provided manifest.

commands.add("git");
commands.add("rev-list");
commands.add("HEAD");
commands.add("-1");
commands.add(env.expand(manifestFile));
} else {
commands.add("git");
commands.add("rev-parse");
commands.add("HEAD");
}
launcher.launch().stderr(logger).stdout(output).pwd(
new FilePath(workspace, ".repo/manifests"))
.cmds(commands).envs(env).join();
Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/hudson/plugins/repo/RepoScm/config.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<f:entry title="Platform" help="/plugin/repo/help-manifestPlatform.html" field="manifestPlatform">
<f:textbox/>
</f:entry>

<f:entry title="IgnoreChanges" help="/plugin/repo/help-ignoreChanges.html" field="ignoreProjects">
<f:textarea rows="3" />
</f:entry>
Expand Down Expand Up @@ -80,6 +80,10 @@
<f:checkbox default="true"/>
</f:entry>

<f:entry title="Poll Manifest" help="/plugin/repo/help-pollManifest.html" field="pollManifest">
<f:checkbox/>
</f:entry>

<f:entry title="Force Sync" help="/plugin/repo/help-forceSync.html" field="forceSync">
<f:checkbox/>
</f:entry>
Expand Down
5 changes: 5 additions & 0 deletions src/main/webapp/help-pollManifest.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div>
<p>
When this is checked, it will only poll manifest file instead of manifest folder.
</p>
</div>
9 changes: 8 additions & 1 deletion src/test/java/hudson/plugins/repo/TestRepoScm.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void testSetIgnoredProjects() {
RepoScm scm = new RepoScm("http://manifesturl");
scm.setIgnoreProjects("");
assertEquals("", scm.getIgnoreProjects());

}

public void testSetIgnoredProjectsKeepsOrder() {
Expand All @@ -58,6 +58,13 @@ public void testResetFirst() {
assertEquals(true, scm.isResetFirst());
}

public void testPollManifest() {
RepoScm scm = new RepoScm("http://manifesturl");
assertEquals(false, scm.isPollManifest());
scm.setPollManifest(true);
assertEquals(true, scm.isPollManifest());
}

public void testCleanFirst() {
RepoScm scm = new RepoScm("http://manifesturl");
assertEquals(false, scm.isCleanFirst());
Expand Down