-
Notifications
You must be signed in to change notification settings - Fork 221
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
Add support for a "manual" SCM Adapter #376
Open
DamnedElric
wants to merge
1
commit into
researchgate:main
Choose a base branch
from
DamnedElric:ManualScmSupport
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
81 changes: 81 additions & 0 deletions
81
src/main/groovy/net/researchgate/release/ManualAdapter.groovy
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,81 @@ | ||
/* | ||
* This file is part of the gradle-release plugin. | ||
* | ||
* (c) Eric Berry | ||
* (c) ResearchGate GmbH | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
package net.researchgate.release | ||
|
||
import org.gradle.api.GradleException | ||
import org.gradle.api.Project | ||
import org.gradle.api.provider.ListProperty | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.Optional | ||
|
||
import java.util.regex.Matcher | ||
|
||
/** | ||
* This ManualAdapter does not interact with any SCM. Instead, it informs the user of manual steps to be executed. | ||
*/ | ||
class ManualAdapter extends BaseScmAdapter { | ||
|
||
private File workingDirectory | ||
|
||
ManualAdapter(Project project, Map<String, Object> attributes) { | ||
super(project, attributes) | ||
} | ||
|
||
// The ManualAdapter is always supported. | ||
@Override | ||
boolean isSupported(File directory) { | ||
true | ||
} | ||
|
||
@Override | ||
void init() { | ||
} | ||
|
||
@Override | ||
void checkCommitNeeded() { | ||
if (!promptYesOrNo('Have all modified files been committed?', true)) { | ||
warnOrThrow(true, 'You have uncommitted changes.') | ||
} | ||
} | ||
|
||
@Override | ||
void checkUpdateNeeded() { | ||
if (!promptYesOrNo('Have all remote modifications been pulled, and local changes pushed?', true)) { | ||
warnOrThrow(true, 'You have unmerged remote changes.') | ||
} | ||
} | ||
|
||
@Override | ||
void createReleaseTag(String message) { | ||
def tagName = tagName() | ||
if (!promptYesOrNo("You should now tag the release. Suggested name: [$tagName]. Did you create the tag?", true)) { | ||
warnOrThrow(true, 'You did not create a release tag.') | ||
} | ||
} | ||
|
||
@Override | ||
void commit(String message) { | ||
if (!promptYesOrNo("You should now commit the changes. Suggested commit message: [$message]. Did you commit the changes?", true)) { | ||
warnOrThrow(true, 'You did not commit the changes.') | ||
} | ||
} | ||
|
||
@Override | ||
void add(File file) { | ||
} | ||
|
||
@Override | ||
void revert() { | ||
def pptsFile = findPropertiesFile().name | ||
println "You should revert the changes to [$pptsFile]" | ||
} | ||
} |
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
78 changes: 78 additions & 0 deletions
78
src/test/groovy/net/researchgate/release/ManualAdapterTests.groovy
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,78 @@ | ||
/* | ||
* This file is part of the gradle-release plugin. | ||
* | ||
* (c) Eric Berry | ||
* (c) ResearchGate GmbH | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
package net.researchgate.release | ||
|
||
import net.researchgate.release.cli.Executor | ||
import org.gradle.api.Project | ||
import org.gradle.testfixtures.ProjectBuilder | ||
import spock.lang.Specification | ||
|
||
class ManualAdapterTests extends Specification { | ||
Project project | ||
ManualAdapter manualAdapter | ||
ByteArrayOutputStream stdout | ||
|
||
File testDir = new File("build/tmp/test/${getClass().simpleName}") | ||
|
||
def setup() { | ||
project = project = ProjectBuilder.builder().withName("ManualAdapterTests").withProjectDir(testDir).build() | ||
project.apply plugin: ReleasePlugin | ||
project.version = '1.0.0' | ||
|
||
def props = project.file("gradle.properties") | ||
props.withWriter {it << "version=${project.version}"} | ||
|
||
manualAdapter = new ManualAdapter(project, [:]) | ||
manualAdapter.executor = Mock(Executor) | ||
// Reassign stdout so we can perform assertions on it | ||
stdout = new ByteArrayOutputStream() | ||
System.out = new PrintStream(stdout) | ||
} | ||
|
||
def "manual adapter is always supported"() { | ||
when: | ||
def supported = manualAdapter.isSupported(null) | ||
|
||
then: | ||
supported == true | ||
} | ||
|
||
def "manual adapter checkCommitNeeded - no commit needed"() { | ||
when: | ||
manualAdapter.checkCommitNeeded() | ||
|
||
then: | ||
stdout.toString().contains('Have all modified files been committed?') | ||
} | ||
|
||
def "manual adapter checkUpdateNeeded - no update needed"() { | ||
when: | ||
manualAdapter.checkUpdateNeeded() | ||
|
||
then: | ||
stdout.toString().contains('Have all remote modifications been pulled') | ||
} | ||
|
||
def "manual adapter commit - no automatic commits"() { | ||
when: | ||
manualAdapter.commit('test message') | ||
|
||
then: | ||
stdout.toString().contains('You should now commit the changes. Suggested commit message: [test message]. Did you commit the changes?') | ||
} | ||
|
||
def "manual adapter revert"() { | ||
when: | ||
manualAdapter.revert() | ||
|
||
then: | ||
stdout.toString().contains('You should revert the changes to [gradle.properties]') | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if it's a good idea to add this by default. Maybe it is, as it will only be executed if no other SCM adapter matches the current environment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could make this one configurable to allow additional adapters to be added.
I think having this as a fallback is not something that most users want as it should somewhat automate the release while this here make everything manual and can be very error prone.