28
28
import org .apache .taverna .robundle .manifest .PathMetadata ;
29
29
import org .commonwl .viewer .github .GitHubService ;
30
30
import org .commonwl .viewer .github .GithubDetails ;
31
+ import org .eclipse .egit .github .core .CommitUser ;
32
+ import org .eclipse .egit .github .core .RepositoryCommit ;
31
33
import org .eclipse .egit .github .core .RepositoryContents ;
34
+ import org .eclipse .egit .github .core .User ;
32
35
import org .slf4j .Logger ;
33
36
import org .slf4j .LoggerFactory ;
34
37
@@ -55,21 +58,23 @@ public class ROBundle {
55
58
56
59
private Bundle bundle ;
57
60
private GithubDetails githubInfo ;
58
- private String commitSha ;
59
61
private Agent thisApp ;
60
62
private int singleFileSizeLimit ;
61
- private Set <HashableAgent > authors = new HashSet <HashableAgent >();
63
+ private Set <HashableAgent > authors = new HashSet <>();
62
64
63
65
// Pattern for extracting version from a cwl file
64
66
private final String CWL_VERSION_REGEX = "cwlVersion:\\ s*\" ?(?:cwl:)?([^\\ s\" ]+)\" ?" ;
65
67
private final Pattern cwlVersionPattern = Pattern .compile (CWL_VERSION_REGEX );
66
68
67
69
/**
68
70
* Creates a new research object bundle for a workflow from a Github repository
71
+ * @param githubService The service for handling Github functionality
69
72
* @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
70
75
* @throws IOException Any API errors which may have occurred
71
76
*/
72
- public ROBundle (GitHubService githubService , GithubDetails githubInfo , String commitSha ,
77
+ public ROBundle (GitHubService githubService , GithubDetails githubInfo ,
73
78
String appName , String appURL , int singleFileSizeLimit ) throws IOException {
74
79
// File size limits
75
80
this .singleFileSizeLimit = singleFileSizeLimit ;
@@ -78,7 +83,6 @@ public ROBundle(GitHubService githubService, GithubDetails githubInfo, String co
78
83
this .bundle = Bundles .createBundle ();
79
84
this .githubInfo = githubInfo ;
80
85
this .githubService = githubService ;
81
- this .commitSha = commitSha ;
82
86
83
87
Manifest manifest = bundle .getManifest ();
84
88
@@ -108,7 +112,7 @@ public ROBundle(GitHubService githubService, GithubDetails githubInfo, String co
108
112
addFiles (repoContents , bundleFiles );
109
113
110
114
// Add combined authors
111
- manifest .setAuthoredBy (new ArrayList <Agent >(authors ));
115
+ manifest .setAuthoredBy (new ArrayList <>(authors ));
112
116
}
113
117
114
118
/**
@@ -140,19 +144,21 @@ private void addFiles(List<RepositoryContents> repoContents, Path path) throws I
140
144
} else if (repoContent .getType ().equals (GitHubService .TYPE_FILE )) {
141
145
142
146
try {
147
+ GithubDetails githubFile = new GithubDetails (githubInfo .getOwner (),
148
+ githubInfo .getRepoName (), githubInfo .getBranch (), repoContent .getPath ());
149
+
143
150
// Where to store the new file in bundle
144
151
Path bundleFilePath = path .resolve (repoContent .getName ());
145
152
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
+
149
157
URI rawURI = new URI ("https://raw.githubusercontent.com/" + githubFile .getOwner () + "/" +
150
158
githubFile .getRepoName () + "/" + commitSha + "/" + githubFile .getPath ());
151
159
152
- // Variable to store file contents
153
- String fileContent = null ;
154
-
155
160
// Download or externally link if oversized
161
+ String fileContent = null ;
156
162
if (repoContent .getSize () <= singleFileSizeLimit ) {
157
163
// Get the content of this file from Github
158
164
fileContent = githubService .downloadFile (githubFile , commitSha );
@@ -185,7 +191,24 @@ private void addFiles(List<RepositoryContents> repoContents, Path path) throws I
185
191
}
186
192
187
193
// 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
+ }
189
212
authors .addAll (fileAuthors );
190
213
aggregation .setAuthoredBy (new ArrayList <Agent >(fileAuthors ));
191
214
0 commit comments