-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGitHubArtifactsCommitter.cfc
More file actions
85 lines (72 loc) · 3.2 KB
/
GitHubArtifactsCommitter.cfc
File metadata and controls
85 lines (72 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
component implements="interfaces.ArtifactsCommitter" {
property name="systemSettings" inject="SystemSettings";
property name="fileSystemUtil" inject="FileSystem";
property name="buildCommitMessage" inject="commandbox:moduleSettings:commandbox-semantic-release:buildCommitMessage";
property name="changelogFileName" inject="commandbox:moduleSettings:commandbox-semantic-release:changelogFileName";
property name="versionPrefix" inject="commandbox:moduleSettings:commandbox-semantic-release:versionPrefix";
property name="targetBranch" inject="commandbox:moduleSettings:commandbox-semantic-release:targetBranch";
property name="options" inject="commandbox:moduleSettings:commandbox-semantic-release";
/**
* Set up jGit for the current repository.
*/
function onDIComplete() {
var builder = createObject( "java", "org.eclipse.jgit.storage.file.FileRepositoryBuilder" ).init();
var gitDir = createObject( "java", "java.io.File" ).init( fileSystemUtil.resolvePath( "" ) & ".git" );
var repository = builder
.setGitDir( gitDir )
.setMustExist( true )
.readEnvironment() // scan environment GIT_* variables
.findGitDir() // scan up the file system tree
.build();
variables.jGit = createObject( "java", "org.eclipse.jgit.api.Git" ).init( repository );
}
/**
* Gives a chance to commit any changes or artifacts produced by the build.
*
* @nextVersion The next version to be published.
* @dryRun Flag to indicate a dry run of the release.
* @verbose Flag to indicate printing out extra information.
* @targetBranch The branch that builds are triggered against.
*/
public void function run(
required string nextVersion,
boolean dryRun = false,
boolean verbose = false,
string targetBranch = variables.targetBranch
) {
if ( dryRun ) {
return;
}
jGit.checkout()
.setName( targetBranch )
.call();
if( options[ "plugins-CommitArtifacts-commitBoxJson" ] == true ) {
jGit.add()
.addFilePattern( "box.json" )
.call();
}
jGit.add()
.addFilePattern( changelogFileName )
.call();
var commit = jGit.commit()
.setMessage( buildCommitMessage )
.setAuthor(
( options[ "plugins-CommitArtifacts-authorName" ] ?: "CommandBox Semantic Release" ),
( options[ "plugins-CommitArtifacts-authorEmail" ] ?: "csr@example.com" )
)
.call();
jGit.tag()
.setMessage( "#versionPrefix##nextVersion#" )
.setName( "#versionPrefix##nextVersion#" )
.call();
var credentials = createObject( "java", "org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider" )
.init( systemSettings.getSystemSetting( "GH_TOKEN" ), "" );
jGit.push()
.setCredentialsProvider( credentials )
.call();
jGit.push()
.setCredentialsProvider( credentials )
.setPushTags()
.call();
}
}