1 module doveralls.doveralls;
2 import doveralls.args, doveralls.config, doveralls.sourcefiles, doveralls.git,
3        doveralls.request;
4 
5 import std.getopt, std.string, std.conv, std.stdio;
6 
7 // Upload data
8 int execute()
9 {
10     CoverallsArgs args;
11 
12     // Get repo information
13     if( Doveralls.repoToken )
14     {
15         args.repo_token = Doveralls.repoToken;
16     }
17     else if( Doveralls.ciServiceName )
18     {
19         args.service_name = Doveralls.ciServiceName;
20         args.service_job_id = Doveralls.ciServiceJobId;
21     }
22     else
23     {
24         writeln( "Please specify ciServiceName and ciServiceJobId or repoToken." );
25         return 1;
26     }
27 
28     // Calculate coverage information
29     args.source_files = getSourceFiles( Doveralls.repoPath );
30 
31     // Get git information
32     args.git = getGitEntry( Doveralls.repoPath );
33 
34     // Get time info
35     args.run_at = getCurrentTime();
36 
37     // Encode json
38     return sendData( args.toJson() );
39 }
40 
41 // Get a string representation of the current time.
42 string getCurrentTime()
43 {
44     // Target: 2013-02-18 00:52:48 -0800
45     import std.array, std.datetime, std.format, std.conv;
46     auto now = Clock.currTime;
47 
48     auto writer = appender!string();
49     writer.formattedWrite(
50         "%d-%d-%d %02d:%02d:%02d %0" ~ (now.utcOffset.hours < 0 ? 3 : 2).to!string ~ "d00",
51         now.year, now.month, now.day,
52         now.hour, now.minute, now.second,
53         now.utcOffset.hours );
54 
55     return writer.data;
56 }