-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #9 Add support for loading default config from a file
- Loading branch information
Showing
8 changed files
with
191 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/com/vincit/go/task/slack/utils/EnvReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.vincit.go.task.slack.utils; | ||
|
||
import in.ashwanthkumar.utils.lang.StringUtils; | ||
|
||
public class EnvReader { | ||
|
||
public EnvReader() {} | ||
|
||
public String get(String name, String defaultValue) { | ||
final String value = System.getenv(name); | ||
if (StringUtils.isNotEmpty(value)) { | ||
return value; | ||
} else { | ||
return defaultValue; | ||
} | ||
} | ||
|
||
public String get(String name) { | ||
return get(name, null); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/vincit/go/task/slack/utils/FileReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,35 @@ | ||
package com.vincit.go.task.slack.utils; | ||
|
||
import com.thoughtworks.go.plugin.api.logging.Logger; | ||
import in.ashwanthkumar.utils.lang.StringUtils; | ||
import org.apache.commons.io.IOUtils; | ||
|
||
import java.io.IOException; | ||
|
||
public class FileReader { | ||
|
||
public static final String FILE_ENCODING = "UTF-8"; | ||
|
||
private Logger logger = Logger.getLoggerFor(FileReader.class); | ||
|
||
public String getFileContents(String filePath) throws IOException { | ||
return IOUtils.toString(getClass().getResourceAsStream(filePath), FILE_ENCODING); | ||
} | ||
|
||
public String getFileContents(String... filePaths) { | ||
for (String filePath : filePaths) { | ||
try { | ||
if (StringUtils.isNotEmpty(filePath)) { | ||
logger.debug("Reading file '" + filePath + "'"); | ||
return getFileContents(filePath); | ||
} else { | ||
logger.debug("Null/empty path, ignore"); | ||
} | ||
} catch (IOException e) { | ||
logger.debug("Could not read file '" + filePath + "'"); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"config": { | ||
"Message": { | ||
"secure": false, | ||
"required": false, | ||
"value": "" | ||
}, | ||
"Title": { | ||
"secure": false, | ||
"required": false, | ||
"value": "" | ||
}, | ||
"IconOrEmoji": { | ||
"secure": false, | ||
"required": false, | ||
"value": "" | ||
}, | ||
"Channel": { | ||
"secure": false, | ||
"required": false, | ||
"value": "" | ||
}, | ||
"ChannelType": { | ||
"secure": false, | ||
"required": false, | ||
"value": "" | ||
}, | ||
"WebhookUrl": { | ||
"secure": false, | ||
"required": false, | ||
"value": "" | ||
}, | ||
"DisplayName": { | ||
"secure": false, | ||
"required": false, | ||
"value": "" | ||
}, | ||
"ColorType": { | ||
"secure": false, | ||
"required": false, | ||
"value": "" | ||
}, | ||
"Color": { | ||
"secure": false, | ||
"required": false, | ||
"value": "" | ||
} | ||
} | ||
} |