Skip to content

Commit 32af998

Browse files
committed
Setup Commit Author
Setting up the author of the Commit. New property "Email" in the GitReposUsersRecord to link the commit to the git user.
1 parent a4b8607 commit 32af998

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

git-gateway/src/main/java/com/axone_io/ignition/git/GatewayScriptModule.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ protected boolean commitImpl(String projectName, String userName, List<String> c
102102
git.add().setUpdate(true).addFilepattern(folderPath).call();
103103
}
104104

105-
git.commit().setMessage(message).call();
105+
CommitCommand commit = git.commit().setMessage(message);
106+
setCommitAuthor(commit, projectName, userName);
107+
commit.call();
108+
106109
git.close();
107110
} catch (GitAPIException e) {
108111
logger.error(e.toString(), e);
@@ -182,7 +185,9 @@ public void setupLocalRepoImpl(String projectName, String userName) throws Excep
182185
git.remoteAdd().setName("origin").setUri(new URIish(gitProjectsConfigRecord.getURI())).call();
183186

184187
git.add().addFilepattern(".").call();
185-
git.commit().setMessage("Initial commit").call();
188+
CommitCommand commit = git.commit().setMessage("Initial commit");
189+
setCommitAuthor(commit, projectName, userName);
190+
commit.call();
186191
PushCommand pushCommand = git.push();
187192
setAuthentication(pushCommand, projectName, userName);
188193
pushCommand.setRemote("origin").setRefSpecs(new RefSpec("master")).call();

git-gateway/src/main/java/com/axone_io/ignition/git/managers/GitManager.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.inductiveautomation.ignition.gateway.images.ImageManager;
1717
import com.inductiveautomation.ignition.gateway.images.ImageRecord;
1818
import org.apache.commons.io.FileUtils;
19+
import org.eclipse.jgit.api.CommitCommand;
1920
import org.eclipse.jgit.api.Git;
2021
import org.eclipse.jgit.api.Status;
2122
import org.eclipse.jgit.api.TransportCommand;
@@ -185,6 +186,17 @@ public static void setAuthentication(TransportCommand command, String projectNam
185186
}
186187
}
187188

189+
public static void setCommitAuthor(CommitCommand command, String projectName, String userName){
190+
try {
191+
GitProjectsConfigRecord gitProjectsConfigRecord = getGitProjectConfigRecord(projectName);
192+
GitReposUsersRecord user = getGitReposUserRecord(gitProjectsConfigRecord, userName);
193+
command.setAuthor("", user.getEmail());
194+
} catch (Exception e){
195+
logger.error("An error occurred while setting up commit author.", e);
196+
}
197+
198+
}
199+
188200
public static GitProjectsConfigRecord getGitProjectConfigRecord(String projectName) throws Exception {
189201
SQuery<GitProjectsConfigRecord> projectQuery = new SQuery<>(GitProjectsConfigRecord.META).eq(GitProjectsConfigRecord.ProjectName, projectName);
190202
GitProjectsConfigRecord gitProjectsConfigRecord = context.getPersistenceInterface().queryOne(projectQuery);

git-gateway/src/main/java/com/axone_io/ignition/git/records/GitReposUsersRecord.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
import com.inductiveautomation.ignition.gateway.web.components.editors.TextAreaEditorSource;
1010
import com.inductiveautomation.ignition.gateway.web.components.user.UserEditForm;
1111
import com.inductiveautomation.ignition.gateway.web.util.UniqueStringValidator;
12+
import org.apache.wicket.markup.html.form.EmailTextField;
1213
import org.apache.wicket.validation.IValidator;
14+
import org.apache.wicket.validation.validator.EmailAddressValidator;
1315
import org.apache.wicket.validation.validator.StringValidator;
1416
import org.slf4j.Logger;
1517
import org.slf4j.LoggerFactory;
@@ -37,10 +39,12 @@ public RecordMeta<?> getMeta() {
3739
public static final StringField IgnitionUser = new StringField(META, "IgnitionUser", SFieldFlags.SPRIMARY_KEY, SFieldFlags.SMANDATORY, SFieldFlags.SDESCRIPTIVE);
3840
public static final StringField SSHKey = new StringField(META, "SSHKey");
3941

40-
public static final StringField UserName = new StringField(META, "UserName");
42+
public static final StringField UserName = new StringField(META, "UserName", SFieldFlags.SMANDATORY, SFieldFlags.SDESCRIPTIVE);
43+
44+
public static final StringField Email = new StringField(META, "Email", SFieldFlags.SMANDATORY, SFieldFlags.SDESCRIPTIVE);
4145
public static final EncodedStringField Password = new EncodedStringField(META, "Password");
4246

43-
static final Category UserProperties = new Category("GitReposUsersRecord.Category.UserProperties", 1000).include(ProjectName, IgnitionUser, SSHKey, UserName, Password);
47+
static final Category UserProperties = new Category("GitReposUsersRecord.Category.UserProperties", 1000).include(ProjectName, IgnitionUser, UserName, Email, SSHKey, Password);
4448

4549
public int getId(){
4650
return this.getInt(Id);
@@ -49,6 +53,7 @@ public int getProjectId(){
4953
return this.getInt(ProjectId);
5054
}
5155
public String getUserName(){ return this.getString(UserName); }
56+
public String getEmail(){ return this.getString(Email); }
5257
public String getIgnitionUser(){ return this.getString(IgnitionUser); }
5358
public String getProjectName(){ return this.getString(ProjectName); }
5459
public String getPassword(){ return this.getString(Password); }
@@ -78,6 +83,11 @@ public int getProjectId(){
7883
UserName.getFormMeta().setFieldDescriptionKeyAddMode("GitReposUsersRecord.UserName.NewDesc");
7984
UserName.getFormMeta().setFieldDescriptionKeyEditMode("GitReposUsersRecord.UserName.EditDesc");
8085

86+
Email.getFormMeta().addValidator(EmailAddressValidator.getInstance());
87+
Email.getFormMeta().setFieldDescriptionKey("GitReposUsersRecord.Email.Desc");
88+
Email.getFormMeta().setFieldDescriptionKeyAddMode("GitReposUsersRecord.Email.NewDesc");
89+
Email.getFormMeta().setFieldDescriptionKeyEditMode("GitReposUsersRecord.Email.EditDesc");
90+
8191
Password.getFormMeta().setFieldDescriptionKey("GitReposUsersRecord.Password.Desc");
8292
Password.getFormMeta().setFieldDescriptionKeyAddMode("GitReposUsersRecord.Password.NewDesc");
8393
Password.getFormMeta().setFieldDescriptionKeyEditMode("GitReposUsersRecord.Password.EditDesc");

git-gateway/src/main/resources/com/axone_io/ignition/git/records/GitReposUsersRecord.properties

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@ SSHKey.NewDesc=The SSH Key of your user git account.
1616
SSHKey.EditDesc=The SSH Key of your user git account.
1717

1818
UserName.Name=Username
19-
UserName.Desc=The username or email of the git account.
20-
UserName.NewDesc=The username or email of the git account.
21-
UserName.EditDesc=The username or email of the git account.
19+
UserName.Desc=The username of the git account.
20+
UserName.NewDesc=The username of the git account.
21+
UserName.EditDesc=The username of the git account.
22+
23+
Email.Name=Email
24+
Email.Desc=The email of the git account.
25+
Email.NewDesc=The email of the git account.
26+
Email.EditDesc=The email of the git account.
2227

2328
Password.Name=Password
2429
Password.Desc=The password or personal access token for the git account.

0 commit comments

Comments
 (0)