Skip to content

Commit

Permalink
Add a way to run a command after a push (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg authored Jul 6, 2024
2 parents c17fdc9 + 1322c93 commit 7bbb884
Show file tree
Hide file tree
Showing 7 changed files with 519 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- A `runAfterPush` command to run a CLI command after the push is complete. ([#51](https://github.com/diffplug/spotless-changelog/pull/51))

## [3.0.2] - 2023-04-06
### Fixed
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ spotlessChangelog { // all defaults
tagPrefix 'release/'
commitMessage 'Published release/{{version}}' // {{version}} will be replaced
tagMessage null // default is null (creates lightweight tag); {{changes}} and {{version}} will be replaced
runAfterPush null // runs a CLI command after the push; {{changes}} and {{version}} will be replaced
remote 'origin'
branch 'main'
// default value is `yes`, but if you set it to `no`, then it will
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2021 DiffPlug
* Copyright (C) 2019-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,6 @@
*/
package com.diffplug.spotless.changelog;


import java.io.File;
import java.io.IOException;
import pl.tlinkowski.annotation.basic.NullOr;
Expand All @@ -31,6 +30,8 @@ public class GitCfg {
public String commitMessage = "Published release/" + COMMIT_MESSAGE_VERSION;
/** Message used in tag, null means lightweight tag. */
public @NullOr String tagMessage = null;
/** Runs a CLI command after the push if not null. */
public @NullOr String runAfterPush = null;
public String remote = "origin";
public String branch = "main";
public String sshStrictHostKeyChecking = "yes";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2023 DiffPlug
* Copyright (C) 2019-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -238,6 +238,11 @@ public void tagMessage(String tagMessage) {
data.gitCfg.tagMessage = tagMessage;
}

/** Runs a CLI command after the push if not null - {{changes}} and {{version}} will be replaced. */
public void runAfterPush(String runAfterPush) {
data.gitCfg.runAfterPush = runAfterPush;
}

/** Default value is 'origin' */
public void remote(String remote) {
data.gitCfg.remote = remote;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2023 DiffPlug
* Copyright (C) 2019-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -247,6 +247,17 @@ public void push() throws IOException, GitAPIException {
GitActions git = data.gitCfg.withChangelog(data.changelogFile, data.model());
git.addAndCommit();
git.tagBranchPush();
if (data.gitCfg.runAfterPush != null) {
try (var runner = new ProcessRunner()) {
var result = runner.shell(data.gitCfg.runAfterPush);
System.out.write(result.stdOut());
System.out.flush();
System.err.write(result.stdErr());
System.err.flush();
} catch (IOException | InterruptedException e) {
throw new GradleException("runAfterPush failed: " + data.gitCfg.runAfterPush, e);
}
}
}
}
}
Loading

0 comments on commit 7bbb884

Please sign in to comment.