Skip to content
This repository was archived by the owner on May 13, 2025. It is now read-only.

Commit 87c5b2e

Browse files
committed
Merge pull request #72 from adamcin/issue-69
resolved issue #69 by getting current user's name and email from EGit github UserService.
2 parents 540e951 + e09ee8d commit 87c5b2e

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

  • github-site-plugin/src/main/java/com/github/maven/plugins/site

github-site-plugin/src/main/java/com/github/maven/plugins/site/SiteMojo.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.util.ArrayList;
4040
import java.util.Arrays;
4141
import java.util.Collections;
42+
import java.util.GregorianCalendar;
4243
import java.util.List;
4344

4445
import org.apache.maven.execution.MavenSession;
@@ -47,13 +48,16 @@
4748
import org.apache.maven.settings.Settings;
4849
import org.eclipse.egit.github.core.Blob;
4950
import org.eclipse.egit.github.core.Commit;
51+
import org.eclipse.egit.github.core.CommitUser;
5052
import org.eclipse.egit.github.core.Reference;
5153
import org.eclipse.egit.github.core.RepositoryId;
5254
import org.eclipse.egit.github.core.Tree;
5355
import org.eclipse.egit.github.core.TreeEntry;
5456
import org.eclipse.egit.github.core.TypedResource;
57+
import org.eclipse.egit.github.core.User;
5558
import org.eclipse.egit.github.core.client.RequestException;
5659
import org.eclipse.egit.github.core.service.DataService;
60+
import org.eclipse.egit.github.core.service.UserService;
5761
import org.eclipse.egit.github.core.util.EncodingUtils;
5862

5963
/**
@@ -423,6 +427,22 @@ public void execute() throws MojoExecutionException {
423427
commit.setMessage(message);
424428
commit.setTree(tree);
425429

430+
try {
431+
UserService userService = new UserService(service.getClient());
432+
User user = userService.getUser();
433+
434+
CommitUser author = new CommitUser();
435+
author.setName(user.getName());
436+
author.setEmail(user.getEmail());
437+
author.setDate(new GregorianCalendar().getTime());
438+
439+
commit.setAuthor(author);
440+
commit.setCommitter(author);
441+
} catch (IOException e) {
442+
throw new MojoExecutionException("Error retrieving user info: "
443+
+ getExceptionMessage(e), e);
444+
}
445+
426446
// Set parent commit SHA-1 if reference exists
427447
if (ref != null)
428448
commit.setParents(Collections.singletonList(new Commit().setSha(ref

0 commit comments

Comments
 (0)