Skip to content

Commit

Permalink
#16 GitHub parsing problem
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoraboeuf committed Jul 31, 2014
1 parent a781498 commit 4e908d5
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class DefaultGitHubClientConfiguratorFactory implements GitHubClientConfi
@Override
public GitHubClientConfigurator getGitHubConfigurator(GitHubConfiguration configuration) {
return client -> {
String oAuth2Token = configuration.getOAuth2Token();
String oAuth2Token = configuration.getOauth2Token();
if (StringUtils.isNotBlank(oAuth2Token)) {
client.setOAuth2Token(oAuth2Token);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.nemerosa.ontrack.extension.github.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import net.nemerosa.ontrack.extension.github.GitHubIssueServiceExtension;
import net.nemerosa.ontrack.extension.issues.model.IssueServiceConfiguration;
Expand Down Expand Up @@ -40,7 +41,7 @@ public class GitHubConfiguration implements UserPasswordConfiguration<GitHubConf
/**
* OAuth2 token
*/
private final String oAuth2Token;
private final String oauth2Token;

/**
* Indexation interval
Expand All @@ -67,7 +68,7 @@ public GitHubConfiguration withPassword(String password) {
repository,
user,
password,
oAuth2Token,
oauth2Token,
indexationInterval
);
}
Expand All @@ -94,7 +95,7 @@ public static Form form() {
.optional()
)
.with(
Text.of("oAuth2Token")
Text.of("oauth2Token")
.label("OAuth2 token")
.length(50)
.optional()
Expand All @@ -117,7 +118,7 @@ public Form asForm() {
.fill("repository", repository)
.fill("user", user)
.fill("password", "")
.fill("oAuth2Token", oAuth2Token)
.fill("oauth2Token", oauth2Token)
.fill("indexationInterval", indexationInterval)
;
}
Expand All @@ -138,6 +139,7 @@ public String getFileAtCommitLink() {
}

@Override
@JsonIgnore
public String getServiceId() {
return GitHubIssueServiceExtension.GITHUB_SERVICE_ID;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public GitConfiguration configure(GitConfiguration configuration, Branch branch)
.withFileAtCommitLink(gitHub.getFileAtCommitLink())
.withIssueServiceConfigurationIdentifier(gitHub.toIdentifier().format());
// User / password
String oAuth2Token = gitHub.getOAuth2Token();
String oAuth2Token = gitHub.getOauth2Token();
String user = gitHub.getUser();
if (StringUtils.isNotBlank(oAuth2Token)) {
gitHubConfig = gitHubConfig
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package net.nemerosa.ontrack.extension.github.model;

import com.fasterxml.jackson.core.JsonProcessingException;
import org.junit.Test;

import static net.nemerosa.ontrack.json.JsonUtils.object;
import static net.nemerosa.ontrack.test.TestUtils.assertJsonRead;
import static net.nemerosa.ontrack.test.TestUtils.assertJsonWrite;

public class GitHubConfigurationTest {

@Test
public void toJson() throws JsonProcessingException {
assertJsonWrite(
object()
.with("name", "ontrack")
.with("repository", "nemerosa/ontrack")
.withNull("user")
.withNull("password")
.with("oauth2Token", "1234567890abcdef")
.with("indexationInterval", 60)
.end(),
new GitHubConfiguration(
"ontrack",
"nemerosa/ontrack",
null,
null,
"1234567890abcdef",
60
)
);
}

@Test
public void fromJson() throws JsonProcessingException {
assertJsonRead(
new GitHubConfiguration(
"ontrack",
"nemerosa/ontrack",
null,
null,
"1234567890abcdef",
60
),
object()
.with("name", "ontrack")
.with("repository", "nemerosa/ontrack")
.withNull("user")
.withNull("password")
.with("indexationInterval", 60)
.with("oauth2Token", "1234567890abcdef")
.with("serviceId", "ontrack") // This field is ignored
.end(),
GitHubConfiguration.class
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public ObjectBuilder(JsonNodeFactory factory) {
this.thisNode = factory.objectNode();
}

public ObjectBuilder withNull(String field) {
return with(field, factory.nullNode());
}

public ObjectBuilder with(String field, int value) {
return with(field, factory.numberNode(value));
}
Expand Down

0 comments on commit 4e908d5

Please sign in to comment.