Class GitService
java.lang.Object
io.skipcheck.tm1.client.service.git.GitService
TM1 Git (schema 11.5.0): ties the model to a Git repository, pushes its objects there
as JSON files (
dimensions/Region.json, …), and pulls them back, on this server
or another.
Pushing and pulling are two steps: push(String, String, GitCommitDetails, GitCredentials, boolean) and pull(String, GitCredentials, GitPlanExecutionMode, boolean) make a plan saying
what would happen (the files, or the operations, such as
Skip Dimensions('Region')), and execute(GitPlan) carries it out.
What TM1 (11.8) does here that you might not expect:
- A plan belongs to the TM1 session that made it: another session can't see it or run it. Executing a plan uses it up; it's gone afterwards.
- The remote needs a commit on the branch to start from: TM1 can't make a repository's first commit, and pushing when the model hasn't changed is refused too (both "Cannot create bare commit").
- A local
file://remote works forinit(String, String, GitCredentials, boolean, GitConfigurationPatch)andstatus(GitCredentials), but not for pushing or pulling ("shallow fetch is not supported by the local transport"); usehttps://,ssh://orgit://. TM1 also refuses a local repository its own user doesn't own. deploy(String, String, String, GitCredentials, boolean, GitConfigurationPatch)is refused while Git is initialized ("Cannot re-deploy"): it's for a server not yet tied to the repository.- A pull compares commits, not the model: it plans the changes between the commit
last deployed and the branch, so an object deleted on the server since is skipped
(
Skip Dimensions('Region')), not brought back.deploy(String, String, String, GitCredentials, boolean, GitConfigurationPatch)brings the whole branch. - The first pull after the remote moves on still plans the commit TM1 had; the next
pull plans the new one. Check the plan's
Commitbefore executing it.
Tie the model to a repository:
// The remote's branch must already have a commit: TM1 can't make the first one
GitCredentials credentials = GitCredentials.password("tm1-bot", token);
return tm1.git().init("https://git.example.com/finance/model.git", "dev", credentials, false, null);
Push the model's changes:
// Plan the commit, look at the files it would push, then push them
GitCommitDetails commit = new GitCommitDetails("Add the Region dimension", "Ada Analyst", "ada@example.com");
return tm1.git()
.push("main", null, commit, credentials, false)
.flatMap(plan -> plan.sourceFiles() == null || plan.sourceFiles().isEmpty() ? Mono.empty()
: tm1.git().execute(plan));
Pull a branch, once the plan is for the commit wanted:
// TM1 11.8 plans the commit it had on the first pull after the remote moves on:
// pull again until the plan is for the commit wanted, then carry it out
return tm1.git()
.pull("main", credentials, null, false)
.filter(plan -> plan.commit() != null && newest.startsWith(plan.commit().id()))
.repeatWhenEmpty(2, attempts -> attempts)
.flatMap(plan -> tm1.git().execute(plan));
-
Constructor Summary
ConstructorsConstructorDescriptionGitService(Tm1Session session) A service sending its requests throughsession. -
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Mono<Void> deploy(String url, String branch, @Nullable String deployment, GitCredentials credentials, boolean force, @Nullable GitConfigurationPatch config) GitDeploy: ties a server not yet tied to a repository, and pullsbranchinto it, in one step.reactor.core.publisher.Mono<Void> tm1.Execute: carries out a plan, pushing its files or pulling its operations.reactor.core.publisher.Mono<Git> init(String url, @Nullable String deployment, GitCredentials credentials, boolean force, @Nullable GitConfigurationPatch config) GitInit: ties the model to a repository.reactor.core.publisher.Mono<GitPlan> One of this session's plans, by ID.reactor.core.publisher.Flux<GitPlan> plans(ODataQuery query) GET GitPlans, streamed: this session's plans not yet executed.reactor.core.publisher.Mono<GitPullPlan> pull(String branch, GitCredentials credentials, @Nullable GitPlanExecutionMode mode, boolean force) GitPull: plans bringing the model up tobranch.reactor.core.publisher.Mono<GitPushPlan> push(String branch, @Nullable String newBranch, GitCommitDetails commit, GitCredentials credentials, boolean force) GitPush: plans a commit of the model's changes on top ofbranch.reactor.core.publisher.Mono<Git> status(GitCredentials credentials) GitStatus: the tie, and what's on the remote.reactor.core.publisher.Mono<Void> uninit(boolean force) GitUninit: unties the model from its repository.
-
Constructor Details
-
GitService
A service sending its requests throughsession.- Parameters:
session- the session
-
-
Method Details
-
init
@Tm1Endpoint("ActionImport GitInit") public reactor.core.publisher.Mono<Git> init(String url, @Nullable String deployment, GitCredentials credentials, boolean force, @Nullable GitConfigurationPatch config) GitInit: ties the model to a repository.- Parameters:
url- the remote's URLdeployment- the deployment's name, such asdev, ornullfor nonecredentials- how to sign in to the remoteforce- whether to replace an existing tieconfig- the Git configuration, ornullfor TM1's- Returns:
- the tie: URL, deployment, deployed commit, and the remote's branches and tags
-
uninit
@Tm1Endpoint("ActionImport GitUninit") public reactor.core.publisher.Mono<Void> uninit(boolean force) GitUninit: unties the model from its repository. The model is left as it is.- Parameters:
force- whether to untie it even with a plan waiting- Returns:
- completes when it's untied
-
status
@Tm1Endpoint("ActionImport GitStatus") public reactor.core.publisher.Mono<Git> status(GitCredentials credentials) GitStatus: the tie, and what's on the remote. Fails with aTm1BadRequestExceptionif Git isn't initialized.- Parameters:
credentials- how to sign in to the remote- Returns:
- the tie
-
push
@Tm1Endpoint("ActionImport GitPush") public reactor.core.publisher.Mono<GitPushPlan> push(String branch, @Nullable String newBranch, GitCommitDetails commit, GitCredentials credentials, boolean force) GitPush: plans a commit of the model's changes on top ofbranch. The plan lists the files;execute(GitPlan)pushes them.- Parameters:
branch- the branch to start from, which must exist on the remotenewBranch- the branch to push to, ornullforbranchcommit- the commit's message and authorcredentials- how to sign in to the remoteforce- whether to push even if the remote moved on- Returns:
- the plan
-
pull
@Tm1Endpoint("ActionImport GitPull") public reactor.core.publisher.Mono<GitPullPlan> pull(String branch, GitCredentials credentials, @Nullable GitPlanExecutionMode mode, boolean force) GitPull: plans bringing the model up tobranch. Pull again if the plan'sCommitisn't the branch's newest: TM1 (11.8) lags a pull behind the remote. The plan lists the operations;execute(GitPlan)carries them out.- Parameters:
branch- the branch to pullcredentials- how to sign in to the remotemode- one commit or each commit in turn, ornullfor TM1's (SingleCommit)force- whether to pull over local changes- Returns:
- the plan
-
deploy
@Tm1Endpoint("ActionImport GitDeploy") public reactor.core.publisher.Mono<Void> deploy(String url, String branch, @Nullable String deployment, GitCredentials credentials, boolean force, @Nullable GitConfigurationPatch config) GitDeploy: ties a server not yet tied to a repository, and pullsbranchinto it, in one step. Refused while Git is initialized.- Parameters:
url- the remote's URLbranch- the branch to deploydeployment- the deployment's name, ornullfor nonecredentials- how to sign in to the remoteforce- whether to deploy over local changesconfig- the Git configuration, ornullfor TM1's- Returns:
- completes when it's deployed;
status(GitCredentials)then shows the commit
-
plans
@Tm1Endpoint("EntitySet GitPlans") public reactor.core.publisher.Flux<GitPlan> plans(ODataQuery query) GET GitPlans, streamed: this session's plans not yet executed. Fails with aTm1BadRequestExceptionif Git isn't initialized.- Parameters:
query- what to select and filter- Returns:
- the plans, each a
GitPushPlanorGitPullPlan
-
plan
One of this session's plans, by ID. TM1 (11.8) sends no@odata.typeforGitPlans('id'), so it couldn't be told apart as a push or a pull; the list says, so the plan is found there.- Parameters:
id- the plan's ID- Returns:
- the plan, or empty if this session has none by that ID (an executed plan is gone)
-
execute
@Tm1Endpoint("Action GitPushPlan/Execute") @Tm1Endpoint("Action GitPullPlan/Execute") public reactor.core.publisher.Mono<Void> execute(GitPlan plan) tm1.Execute: carries out a plan, pushing its files or pulling its operations. The plan is used up.- Parameters:
plan- the plan, frompush(String, String, GitCommitDetails, GitCredentials, boolean),pull(String, GitCredentials, GitPlanExecutionMode, boolean)orplans(ODataQuery)- Returns:
- completes when it's done
-