Skip to content

Create CommitToGit Command#1912

Merged
rain-on merged 92 commits intomainfrom
tmm/new_commit_to_git
May 8, 2026
Merged

Create CommitToGit Command#1912
rain-on merged 92 commits intomainfrom
tmm/new_commit_to_git

Conversation

@rain-on
Copy link
Copy Markdown
Contributor

@rain-on rain-on commented May 5, 2026

The commitToGit step is basically the script step, but is also able to copy some of the steps packages into the target git repository.

Thus, there is a single variable which contains a json blob defining which packages should be used for copying (and thus should only be substituted with non-sensitive variables).

The step executes the following in order:
Phase 1:

  • Clone target repository into known location, and create variable containing its working directory

Phase 2:

  • Unpack primary package, and all associated packages
  • Unpack all git dependencies
  • Substitute all variables into the script if it is inline.

Phase 3:

  • Substitute all variables into packages which are not listed in the "input file metadata"

Phase 4:

  • Substitute non-sensitive values into all packages and git-deps in the "input file metadata"
  • Copy the specified files into the repository created in Phase 1

Phase 5:

  • Execute the script provided (run from deployment directory, but can access respository via variable)

Phase 6:

  • Commit changes to repo
  • Push to remote and create a PR if required (as per Argo step)
  • Raise output variables.

⚠️ Does this change require a corresponding Server Change?
⚠️ If so - please add a "Requires Server Change" label to this PR!

rain-on and others added 30 commits March 27, 2026 16:34
…teParser

Also fix dangling references in TransformAndCommitToGitCommand left by
the removed files: drop the stale CommitWorkspaceToGitRepositoryConvention
AddRange block and correct pathToPackage -> packageFile so the build is clean.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…Connection

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ntions

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file has been superseded by inline delegates and is no longer needed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…mand

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@rain-on rain-on requested review from flin-8 and zentron May 5, 2026 06:45
Comment on lines +359 to +363
public const string Url = "Octopus.Action.Git.TargetRepositoryUrl";
public const string Username = "Octopus.Action.Git.TargetRepositoryUsername";
public const string Password = "Octopus.Action.Git.TargetRepositoryPassword";
public const string Reference = "Octopus.Action.Git.TargetRepositoryBranch";
public const string DestinationPath = "Octopus.Action.Git.DestinationPath";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mix between target and destination confuzzled me...might be just my brain tho.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, we'' consolidate on the TargetRepository naming convention

var dependencyNames = new List<string>();
// we reverse the order of the array so that we maintain the order that sources at the top take higher precendences (i.e. are adding to the --values list later),
// however, within a source, the file path order must be maintained (for consistency) so that later file paths take higher precendence
foreach (var jToken in parsedJsonArray.Select((json, index) => json))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the reversal mentioned in the comment? Am I missing something?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup - stolen from another step - this is not true in this context - removed.

this.configFactory = configFactory;
}

public override int Execute(string[] commandLineArguments)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 This feels like a massive method. Seems like there are 4 pieces perhaps

  1. The file copy
  2. the transformation
  3. the commit and
  4. The script substitution.

Are they worth separating out?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup - broke this up into separate functiuons to represent each phase

var deployment = new RunningDeployment(pathToPackage, variables);
var baseWorkingDirectory = deployment.CurrentDirectory;
var repositoryConfig = configFactory.CreateRepositoryConfig(deployment);
var repositoryFactory = new RepositoryFactory(log, fileSystem, baseWorkingDirectory, gitVendorPullRequestClientResolver, clock);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be injected?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think so - as we don't know the baseWorking directory until after the deployment is created

var commitParams = repositoryConfig!.CommitParameters;
var updater = new RepositoryUpdater(commitParams, log, new UserDefinedCommitMessageGenerator(commitParams.Description));

//TODO(tmm): This is a smell, shouldn't need the FileUpdateResult here :/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be To-Done?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've cleaned it up - its not great, but its better.

var extractAllPackages = new List<IConvention>
{
//we only want to include files which are NOT explicitly referenced as dependencies (i.e. we have files which are to be copied into the repo (referenced in variable), and some which should just be used for script dependencies.
new StageDependenciesConvention(pathToPackage, fileSystem, new CombinedPackageExtractor(log, fileSystem, variables, commandLineRunner), new PackageVariablesFactory()),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PackageVariablesFactory() is created here and again below. Is that necessary?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its super light - and now that this broken out to function-per-phase, it make the dependency less simple

Copy link
Copy Markdown
Contributor

@Jtango18 Jtango18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly questions from me, but nothing too dire blocking here.

@rain-on rain-on merged commit 6c820fd into main May 8, 2026
33 checks passed
@rain-on rain-on deleted the tmm/new_commit_to_git branch May 8, 2026 03:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants