@sasjs/core 4.43.1 → 4.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/base/mf_getgitbranch.sas +37 -0
- package/base/mf_readfile.sas +63 -0
- package/base/mp_gitlog.sas +104 -0
- package/base/mp_gitstatus.sas +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief Retrieves the current branch from a local GIT repo
|
|
4
|
+
@details In a local git repository, the current branch is always available in
|
|
5
|
+
the `.git/HEAD` file in a format like this: `ref: refs/heads/master`
|
|
6
|
+
|
|
7
|
+
This macro simply reads the file and returns the last word (eg `master`).
|
|
8
|
+
|
|
9
|
+
Example usage:
|
|
10
|
+
|
|
11
|
+
%let gitdir=%sysfunc(pathname(work))/core;
|
|
12
|
+
%let repo=https://github.com/sasjs/core;
|
|
13
|
+
%put source clone rc=%sysfunc(GITFN_CLONE(&repo,&gitdir));
|
|
14
|
+
|
|
15
|
+
%put The current branch is %mf_getgitbranch(&gitdir);
|
|
16
|
+
|
|
17
|
+
@param [in] gitdir The directory containing the GIT repository
|
|
18
|
+
|
|
19
|
+
<h4> SAS Macros </h4>
|
|
20
|
+
@li mf_readfile.sas
|
|
21
|
+
|
|
22
|
+
<h4> Related Macros </h4>
|
|
23
|
+
@li mp_gitadd.sas
|
|
24
|
+
@li mp_gitlog.sas
|
|
25
|
+
@li mp_gitreleaseinfo.sas
|
|
26
|
+
@li mp_gitstatus.sas
|
|
27
|
+
|
|
28
|
+
@version 9.2
|
|
29
|
+
@author Allan Bowe
|
|
30
|
+
**/
|
|
31
|
+
|
|
32
|
+
%macro mf_getgitbranch(gitdir
|
|
33
|
+
)/*/STORE SOURCE*/;
|
|
34
|
+
|
|
35
|
+
%scan(%mf_readfile(&gitdir/.git/HEAD),-1)
|
|
36
|
+
|
|
37
|
+
%mend mf_getgitbranch;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief Reads the first line of a file using pure macro
|
|
4
|
+
@details Reads the first line of a file and returns it. Future versions may
|
|
5
|
+
read each line into a macro variable array.
|
|
6
|
+
|
|
7
|
+
Generally, reading data into macro variables is not great as certain
|
|
8
|
+
nonprintable characters (such as CR, LF) may be dropped in the conversion.
|
|
9
|
+
|
|
10
|
+
Usage:
|
|
11
|
+
|
|
12
|
+
%mf_writefile(&sasjswork/myfile.txt,l1=some content,l2=more content)
|
|
13
|
+
|
|
14
|
+
%put %mf_readfile(&sasjswork/myfile.txt);
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@param [in] fpath Full path to file to be read
|
|
18
|
+
|
|
19
|
+
<h4> Related Macros </h4>
|
|
20
|
+
@li mf_deletefile.sas
|
|
21
|
+
@li mf_writefile.sas
|
|
22
|
+
@li mf_readfile.test.sas
|
|
23
|
+
|
|
24
|
+
@version 9.2
|
|
25
|
+
@author Allan Bowe
|
|
26
|
+
**/
|
|
27
|
+
/** @cond */
|
|
28
|
+
|
|
29
|
+
%macro mf_readfile(fpath
|
|
30
|
+
)/*/STORE SOURCE*/;
|
|
31
|
+
%local fref rc fid fcontent;
|
|
32
|
+
|
|
33
|
+
/* check file exists */
|
|
34
|
+
%if %sysfunc(filename(fref,&fpath)) ne 0 %then %do;
|
|
35
|
+
%put &=fref &=fpath;
|
|
36
|
+
%put %str(ERR)OR: %sysfunc(sysmsg());
|
|
37
|
+
%return;
|
|
38
|
+
%end;
|
|
39
|
+
|
|
40
|
+
%let fid=%sysfunc(fopen(&fref,I));
|
|
41
|
+
|
|
42
|
+
%if &fid=0 %then %do;
|
|
43
|
+
%put %str(ERR)OR: %sysfunc(sysmsg());
|
|
44
|
+
%return;
|
|
45
|
+
%end;
|
|
46
|
+
|
|
47
|
+
%if %sysfunc(fread(&fid)) = 0 %then %do;
|
|
48
|
+
%let rc=%sysfunc(fget(&fid,fcontent,65534));
|
|
49
|
+
&fcontent
|
|
50
|
+
%end;
|
|
51
|
+
|
|
52
|
+
/*
|
|
53
|
+
%do %while(%sysfunc(fread(&fid)) = 0);
|
|
54
|
+
%let rc=%sysfunc(fget(&fid,fcontent,65534));
|
|
55
|
+
&fcontent
|
|
56
|
+
%end;
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
%let rc=%sysfunc(fclose(&fid));
|
|
60
|
+
%let rc=%sysfunc(filename(&fref));
|
|
61
|
+
|
|
62
|
+
%mend mf_readfile;
|
|
63
|
+
/** @endcond */
|
|
@@ -0,0 +1,104 @@
|
|
|
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:
|
|
8
|
+
https://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
|
+
**/
|
|
53
|
+
|
|
54
|
+
%macro mp_gitlog(gitdir,outds=work.mp_gitlog,mdebug=0,filter=BRANCHONLY,nobs=0);
|
|
55
|
+
|
|
56
|
+
%local varlist i var;
|
|
57
|
+
%let varlist=author children_ids committer committer_email email id
|
|
58
|
+
in_current_branch parent_ids stash time ;
|
|
59
|
+
|
|
60
|
+
data &outds;
|
|
61
|
+
LENGTH gitdir branch $ 1024 message $4000 &varlist $128 commit_time_num 8.
|
|
62
|
+
commit_time_str $32;
|
|
63
|
+
call missing (of _all_);
|
|
64
|
+
branch="%mf_getgitbranch(&gitdir)";
|
|
65
|
+
gitdir=symget('gitdir');
|
|
66
|
+
rc=git_status_free(trim(gitdir));
|
|
67
|
+
if rc=-1 then do;
|
|
68
|
+
put "The libgit2 library is unavailable and no Git operations can be used.";
|
|
69
|
+
put "See: https://stackoverflow.com/questions/74082874";
|
|
70
|
+
stop;
|
|
71
|
+
end;
|
|
72
|
+
else if rc=-2 then do;
|
|
73
|
+
put "The libgit2 library is available, but the status function failed.";
|
|
74
|
+
put "See the log for details.";
|
|
75
|
+
stop;
|
|
76
|
+
end;
|
|
77
|
+
entries=git_commit_log(trim(gitdir));
|
|
78
|
+
do n=1 to entries;
|
|
79
|
+
|
|
80
|
+
%do i=1 %to %sysfunc(countw(&varlist message));
|
|
81
|
+
%let var=%scan(&varlist message,&i,%str( ));
|
|
82
|
+
rc=git_commit_get(n,trim(gitdir),"&var",&var);
|
|
83
|
+
%end;
|
|
84
|
+
/* convert unix time to SAS time - https://4gl.uk/corelink0 */
|
|
85
|
+
/* Number of seconds between 01JAN1960 and 01JAN1970: 315619200 */
|
|
86
|
+
format commit_time_num datetime19.;
|
|
87
|
+
commit_time_num=sum(input(cats(time),best.),315619200);
|
|
88
|
+
commit_time_str=put(commit_time_num,datetime19.);
|
|
89
|
+
%if &mdebug=1 %then %do;
|
|
90
|
+
putlog (_all_)(=);
|
|
91
|
+
%end;
|
|
92
|
+
if "&filter"="BRANCHONLY" then do;
|
|
93
|
+
if cats(in_current_branch)='TRUE' then output;
|
|
94
|
+
end;
|
|
95
|
+
else output;
|
|
96
|
+
%if &nobs>0 %then %do;
|
|
97
|
+
if n ge &nobs then stop;
|
|
98
|
+
%end;
|
|
99
|
+
end;
|
|
100
|
+
rc=git_commit_free(trim(gitdir));
|
|
101
|
+
keep gitdir branch &varlist message time commit_time_num commit_time_str;
|
|
102
|
+
run;
|
|
103
|
+
|
|
104
|
+
%mend mp_gitlog;
|
package/base/mp_gitstatus.sas
CHANGED
package/package.json
CHANGED