Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions pj-report/src/main/java/com/g2forge/project/report/Billing.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public static void main(String[] args) throws Throwable {
IStandardCommand.main(args, new Billing());
}

protected final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("yyyy/MM/dd");
protected static final DateTimeFormatter DATE_FORMAT_SLASH = DateTimeFormatter.ofPattern("yyyy/MM/dd");

protected List<Change> computeChanges(ExtendedJiraRestClient client, Server server, Request request, IFunction1<User, String> userToFriendly, String issueKey, ZonedDateTime start, ZonedDateTime end) throws InterruptedException, ExecutionException {
final Issue issue = client.getIssueClient().getIssue(issueKey, HCollection.asList(IssueRestClient.Expandos.CHANGELOG)).get();
Expand Down Expand Up @@ -212,17 +212,19 @@ protected List<Issue> findRelevantIssues(ExtendedJiraRestClient client, String j
final List<Issue> retVal = new ArrayList<>();
for (String user : users) {
log.info("Finding issues for {}", user);
final String compositeJQL = String.format("issuekey IN updatedBy(%1$s, \"%2$s\", \"%3$s\")", user, start.format(DATE_FORMAT), end.format(DATE_FORMAT)) + ((jql == null) ? "" : (" AND " + jql));
final int desiredMax = 500;
int base = 0;
final String compositeJQL = String.format("issuekey IN updatedBy(%1$s, \"%2$s\", \"%3$s\")", user, start.format(DATE_FORMAT_SLASH), end.format(DATE_FORMAT_SLASH)) + ((jql == null) ? "" : (" AND " + jql));
final int desiredMax = 5000;
int currentIssuesPerUser = 0;
String nextPageToken = null;
while (true) {
final SearchResult searchResult = client.getSearchClient().searchJql(compositeJQL, desiredMax, base, null).get();
final int actualMax = searchResult.getMaxResults();
log.info("\tGot issues {} to {} of {}", base, base + Math.min(actualMax, searchResult.getTotal() - base), searchResult.getTotal());

retVal.addAll(HCollection.asListIterable(searchResult.getIssues()));
if ((base + actualMax) >= searchResult.getTotal()) break;
else base += actualMax;
final SearchResult searchResult = client.getSearchClient().enhancedSearchJql(compositeJQL, desiredMax, nextPageToken, HCollection.asSet("*all"), null).get();
final List<Issue> issues = HCollection.asListIterable(searchResult.getIssues());
retVal.addAll(issues);
nextPageToken = searchResult.getNextPageToken();
currentIssuesPerUser += issues.size();
log.info("\tFound {} ({}) issues, {}", issues.size(), currentIssuesPerUser, nextPageToken == null ? "none remaining" : "more coming");
retVal.addAll(issues);
if (nextPageToken == null) break;
}
}
return retVal;
Expand All @@ -246,6 +248,8 @@ protected List<Change> examineIssue(final ExtendedJiraRestClient client, Server

public static final DateTimeFormatter DATETIME_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm[:ss]");

public static final DateTimeFormatter DATE_FORMAT_DASH = DateTimeFormatter.ofPattern("yyyy-MM-dd");

@Override
public IExit invoke(CommandInvocation<InputStream, PrintStream> invocation) throws Throwable {
HLog.getLogControl().setLogLevel(Level.INFO);
Expand Down Expand Up @@ -315,7 +319,8 @@ public IExit invoke(CommandInvocation<InputStream, PrintStream> invocation) thro
billLines.add(new BillLine(component, assignees, issue, summary, hours, ranges.toString().strip(), link));
}
}
final Path outputFile = Filename.replaceExtension(arguments.getRequest(), "csv");

final Path outputFile = arguments.getRequest().getParent().resolve(Filename.fromPath(arguments.getRequest()).getFirst() + " " + DATE_FORMAT_DASH.format(request.getStart()) + " - " + DATE_FORMAT_DASH.format(request.getEnd()) + ".csv");
log.info("Writing bill to {}", outputFile);
BillLine.getMapper().write(billLines, outputFile);

Expand Down