2828import org .apache .taverna .robundle .manifest .PathMetadata ;
2929import org .commonwl .viewer .github .GitHubService ;
3030import org .commonwl .viewer .github .GithubDetails ;
31+ import org .eclipse .egit .github .core .CommitUser ;
32+ import org .eclipse .egit .github .core .RepositoryCommit ;
3133import org .eclipse .egit .github .core .RepositoryContents ;
34+ import org .eclipse .egit .github .core .User ;
3235import org .slf4j .Logger ;
3336import org .slf4j .LoggerFactory ;
3437
@@ -55,21 +58,23 @@ public class ROBundle {
5558
5659 private Bundle bundle ;
5760 private GithubDetails githubInfo ;
58- private String commitSha ;
5961 private Agent thisApp ;
6062 private int singleFileSizeLimit ;
61- private Set <HashableAgent > authors = new HashSet <HashableAgent >();
63+ private Set <HashableAgent > authors = new HashSet <>();
6264
6365 // Pattern for extracting version from a cwl file
6466 private final String CWL_VERSION_REGEX = "cwlVersion:\\ s*\" ?(?:cwl:)?([^\\ s\" ]+)\" ?" ;
6567 private final Pattern cwlVersionPattern = Pattern .compile (CWL_VERSION_REGEX );
6668
6769 /**
6870 * Creates a new research object bundle for a workflow from a Github repository
71+ * @param githubService The service for handling Github functionality
6972 * @param githubInfo The information necessary to access the Github directory associated with the RO
73+ * @param appName The name of the application from properties, for attribution
74+ * @param appURL The URL of the application from properties, for attribution
7075 * @throws IOException Any API errors which may have occurred
7176 */
72- public ROBundle (GitHubService githubService , GithubDetails githubInfo , String commitSha ,
77+ public ROBundle (GitHubService githubService , GithubDetails githubInfo ,
7378 String appName , String appURL , int singleFileSizeLimit ) throws IOException {
7479 // File size limits
7580 this .singleFileSizeLimit = singleFileSizeLimit ;
@@ -78,7 +83,6 @@ public ROBundle(GitHubService githubService, GithubDetails githubInfo, String co
7883 this .bundle = Bundles .createBundle ();
7984 this .githubInfo = githubInfo ;
8085 this .githubService = githubService ;
81- this .commitSha = commitSha ;
8286
8387 Manifest manifest = bundle .getManifest ();
8488
@@ -108,7 +112,7 @@ public ROBundle(GitHubService githubService, GithubDetails githubInfo, String co
108112 addFiles (repoContents , bundleFiles );
109113
110114 // Add combined authors
111- manifest .setAuthoredBy (new ArrayList <Agent >(authors ));
115+ manifest .setAuthoredBy (new ArrayList <>(authors ));
112116 }
113117
114118 /**
@@ -140,19 +144,21 @@ private void addFiles(List<RepositoryContents> repoContents, Path path) throws I
140144 } else if (repoContent .getType ().equals (GitHubService .TYPE_FILE )) {
141145
142146 try {
147+ GithubDetails githubFile = new GithubDetails (githubInfo .getOwner (),
148+ githubInfo .getRepoName (), githubInfo .getBranch (), repoContent .getPath ());
149+
143150 // Where to store the new file in bundle
144151 Path bundleFilePath = path .resolve (repoContent .getName ());
145152
146- // Raw URI of the bundle
147- GithubDetails githubFile = new GithubDetails (githubInfo .getOwner (),
148- githubInfo .getRepoName (), githubInfo .getBranch (), repoContent .getPath ());
153+ // Get commits
154+ List <RepositoryCommit > commitsOnFile = githubService .getCommits (githubFile );
155+ String commitSha = commitsOnFile .get (0 ).getSha ();
156+
149157 URI rawURI = new URI ("https://raw.githubusercontent.com/" + githubFile .getOwner () + "/" +
150158 githubFile .getRepoName () + "/" + commitSha + "/" + githubFile .getPath ());
151159
152- // Variable to store file contents
153- String fileContent = null ;
154-
155160 // Download or externally link if oversized
161+ String fileContent = null ;
156162 if (repoContent .getSize () <= singleFileSizeLimit ) {
157163 // Get the content of this file from Github
158164 fileContent = githubService .downloadFile (githubFile , commitSha );
@@ -185,7 +191,24 @@ private void addFiles(List<RepositoryContents> repoContents, Path path) throws I
185191 }
186192
187193 // Add authors from github commits to the file
188- Set <HashableAgent > fileAuthors = githubService .getContributors (githubFile , commitSha );
194+ Set <HashableAgent > fileAuthors = new HashSet <>();
195+ for (RepositoryCommit commit : commitsOnFile ) {
196+ User author = commit .getAuthor ();
197+ CommitUser commitAuthor = commit .getCommit ().getAuthor ();
198+
199+ // If there is author information for this commit in some form
200+ if (author != null || commitAuthor != null ) {
201+ // Create a new agent and add as much detail as possible
202+ HashableAgent newAgent = new HashableAgent ();
203+ if (author != null ) {
204+ newAgent .setUri (new URI (author .getHtmlUrl ()));
205+ }
206+ if (commitAuthor != null ) {
207+ newAgent .setName (commitAuthor .getName ());
208+ }
209+ fileAuthors .add (newAgent );
210+ }
211+ }
189212 authors .addAll (fileAuthors );
190213 aggregation .setAuthoredBy (new ArrayList <Agent >(fileAuthors ));
191214
0 commit comments