Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_gitlog.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Creates a dataset with the commit history of a local repository
4 @details Returns the commit history from a local repository. The name of the
5 branch is also returned.
6
7 More details here:
8https://documentation.sas.com/doc/ko/pgmsascdc/v_033/lefunctionsref/n1qo5miyvry1nen111js203hlwrh.htm
9
10 Usage:
11
12 %let gitdir=%sysfunc(pathname(work))/core;
13 %let repo=https://github.com/sasjs/core;
14 %put source clone rc=%sysfunc(GITFN_CLONE(&repo,&dir));
15
16 %mp_gitlog(&gitdir,outds=work.mp_gitlog)
17
18 @param [in] gitdir The directory containing the GIT repository
19 @param [in] filter= (BRANCHONLY) To return only the commits for the current
20 branch, use BRANCHONLY (the default). Anything else will return the entire
21 commit history.
22 @param [out] outds= (work.mp_gitlog) The output dataset to create.
23 All vars are $128 except `message` which is $4000.
24 @li author returns the author who submitted the commit.
25 @li children_ids returns a list of the children commit IDs
26 @li committer returns the name of the committer.
27 @li committer_email returns the email of the committer.
28 @li email returns the email of the commit author.
29 @li id returns the commit ID of the commit object.
30 @li in_current_branch returns "TRUE" or "FALSE" to indicate if the commit is
31 in the current branch.
32 @li message returns the commit message.
33 @li parent_ids returns a list of the parent commit IDs.
34 @li stash returns "TRUE" or "FALSE" to indicate if the commit is a stash
35 commit.
36 @li time returns the time of the commit as numeric string
37 @li commit_time_num time of the commit as numeric SAS datetime
38 @li commit_time_str the commit_time_num variable cast as string
39
40 @param [in] mdebug= (0) Set to 1 to enable DEBUG messages
41 @param [in] nobs= (0) Set to an integer greater than 0 to restrict the number
42 of rows returned
43
44 <h4> SAS Macros </h4>
45 @li mf_getgitbranch.sas
46
47 <h4> Related Files </h4>
48 @li mp_gitadd.sas
49 @li mp_gitreleaseinfo.sas
50 @li mp_gitstatus.sas
51
52 @sasjslint {"maxLineLength": 100}
53**/
54
55%macro mp_gitlog(gitdir,outds=work.mp_gitlog,mdebug=0,filter=BRANCHONLY,nobs=0);
56
57%local varlist i var;
58%let varlist=author children_ids committer committer_email email id
59 in_current_branch parent_ids stash time ;
60
61data &outds;
62 LENGTH gitdir branch $ 1024 message $4000 &varlist $128 commit_time_num 8.
63 commit_time_str $32;
64 call missing (of _all_);
65 branch="%mf_getgitbranch(&gitdir)";
66 gitdir=symget('gitdir');
67 rc=git_status_free(trim(gitdir));
68 if rc=-1 then do;
69 put "The libgit2 library is unavailable and no Git operations can be used.";
70 put "See: https://stackoverflow.com/questions/74082874";
71 stop;
72 end;
73 else if rc=-2 then do;
74 put "The libgit2 library is available, but the status function failed.";
75 put "See the log for details.";
76 stop;
77 end;
78 entries=git_commit_log(trim(gitdir));
79 do n=1 to entries;
80
81 %do i=1 %to %sysfunc(countw(&varlist message));
82 %let var=%scan(&varlist message,&i,%str( ));
83 rc=git_commit_get(n,trim(gitdir),"&var",&var);
84 %end;
85 /* convert unix time to SAS time - https://4gl.uk/corelink0 */
86 /* Number of seconds between 01JAN1960 and 01JAN1970: 315619200 */
87 format commit_time_num datetime19.;
88 commit_time_num=sum(input(cats(time),best.),315619200);
89 commit_time_str=put(commit_time_num,datetime19.);
90 %if &mdebug=1 %then %do;
91 putlog (_all_)(=);
92 %end;
93 if "&filter"="BRANCHONLY" then do;
94 if cats(in_current_branch)='TRUE' then output;
95 end;
96 else output;
97 %if &nobs>0 %then %do;
98 if n ge &nobs then stop;
99 %end;
100 end;
101 rc=git_commit_free(trim(gitdir));
102 keep gitdir branch &varlist message time commit_time_num commit_time_str;
103run;
104
105%mend mp_gitlog;