@sasjs/core 4.43.1 → 4.44.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.
@@ -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,99 @@
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
+
42
+ <h4> SAS Macros </h4>
43
+ @li mf_getgitbranch.sas
44
+
45
+ <h4> Related Files </h4>
46
+ @li mp_gitadd.sas
47
+ @li mp_gitreleaseinfo.sas
48
+ @li mp_gitstatus.sas
49
+
50
+ **/
51
+
52
+ %macro mp_gitlog(gitdir,outds=work.mp_gitlog,mdebug=0,filter=BRANCHONLY);
53
+
54
+ %local varlist i var;
55
+ %let varlist=author children_ids committer committer_email email id
56
+ in_current_branch parent_ids stash time ;
57
+
58
+ data &outds;
59
+ LENGTH gitdir branch $ 1024 message $4000 &varlist $128 commit_time_num 8.
60
+ commit_time_str $32;
61
+ call missing (of _all_);
62
+ branch="%mf_getgitbranch(&gitdir)";
63
+ gitdir=symget('gitdir');
64
+ rc=git_status_free(trim(gitdir));
65
+ if rc=-1 then do;
66
+ put "The libgit2 library is unavailable and no Git operations can be used.";
67
+ put "See: https://stackoverflow.com/questions/74082874";
68
+ stop;
69
+ end;
70
+ else if rc=-2 then do;
71
+ put "The libgit2 library is available, but the status function failed.";
72
+ put "See the log for details.";
73
+ stop;
74
+ end;
75
+ entries=git_commit_log(trim(gitdir));
76
+ do n=1 to entries;
77
+
78
+ %do i=1 %to %sysfunc(countw(&varlist message));
79
+ %let var=%scan(&varlist message,&i,%str( ));
80
+ rc=git_commit_get(n,trim(gitdir),"&var",&var);
81
+ %end;
82
+ /* convert unix time to SAS time - https://4gl.uk/corelink0 */
83
+ /* Number of seconds between 01JAN1960 and 01JAN1970: 315619200 */
84
+ format commit_time_num datetime19.;
85
+ commit_time_num=sum(input(cats(time),best.),315619200);
86
+ commit_time_str=put(commit_time_num,datetime19.);
87
+ %if &mdebug=1 %then %do;
88
+ putlog (_all_)(=);
89
+ %end;
90
+ if "&filter"="BRANCHONLY" then do;
91
+ if cats(in_current_branch)='TRUE' then output;
92
+ end;
93
+ else output;
94
+ end;
95
+ rc=git_commit_free(trim(gitdir));
96
+ keep gitdir branch &varlist message time commit_time_num commit_time_str;
97
+ run;
98
+
99
+ %mend mp_gitlog;
@@ -60,7 +60,7 @@ data &outds;
60
60
  putlog (_all_)(=);
61
61
  %end;
62
62
  end;
63
- rc=git_status_free(gitdir);
63
+ rc=git_status_free(trim(gitdir));
64
64
  drop rc cnt;
65
65
  run;
66
66
 
package/package.json CHANGED
@@ -35,5 +35,5 @@
35
35
  "devDependencies": {
36
36
  "@sasjs/cli": "3.13.0"
37
37
  },
38
- "version": "4.43.1"
38
+ "version": "4.44.0"
39
39
  }