@sasjs/utils 2.49.1 → 2.49.2

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.
@@ -101,8 +101,7 @@ data &out_ds(compress=no
101
101
  if did=0 then do;
102
102
  putlog "NOTE: This directory is empty, or does not exist - &path";
103
103
  msg=sysmsg();
104
- put msg;
105
- put _all_;
104
+ put (_all_)(=);
106
105
  stop;
107
106
  end;
108
107
  /* attribute is OS-dependent - could be "Directory" or "Directory Name" */
@@ -0,0 +1,45 @@
1
+ /**
2
+ @file
3
+ @brief Stages files in a GIT repo
4
+ @details Uses the output dataset from mp_gitstatus.sas to determine the files
5
+ that should be staged.
6
+
7
+ If `STAGED ne "TRUE"` then the file is staged.
8
+
9
+ Usage:
10
+
11
+ %let dir=%sysfunc(pathname(work))/core;
12
+ %let repo=https://github.com/sasjs/core;
13
+ %put source clone rc=%sysfunc(GITFN_CLONE(&repo,&dir));
14
+ %mf_writefile(&dir/somefile.txt,l1=some content)
15
+ %mf_deletefile(&dir/package.json)
16
+ %mp_gitstatus(&dir,outds=work.gitstatus)
17
+
18
+ %mp_gitadd(&dir,inds=work.gitstatus)
19
+
20
+ @param [in] gitdir The directory containing the GIT repository
21
+ @param [in] inds= (work.mp_gitadd) The input dataset with the list of files
22
+ to stage. Will accept the output from mp_gitstatus(), else just use a table
23
+ with the following columns:
24
+ @li path $1024 - relative path to the file in the repo
25
+ @li staged $32 - whether the file is staged (TRUE or FALSE)
26
+ @li status $64 - either new, deleted, or modified
27
+
28
+ @param [in] mdebug= (0) Set to 1 to enable DEBUG messages
29
+
30
+ <h4> Related Files </h4>
31
+ @li mp_gitadd.test.sas
32
+ @li mp_gitstatus.sas
33
+
34
+ **/
35
+
36
+ %macro mp_gitadd(gitdir,inds=work.mp_gitadd,mdebug=0);
37
+
38
+ data _null_;
39
+ set &inds;
40
+ if STAGED ne "TRUE";
41
+ rc=git_index_add("&gitdir",cats(path),status);
42
+ if rc ne 0 or &mdebug=1 then put rc=;
43
+ run;
44
+
45
+ %mend mp_gitadd;
@@ -0,0 +1,74 @@
1
+ /**
2
+ @file
3
+ @brief Pulls latest release info from a GIT repository
4
+ @details Useful for grabbing the latest version number or other attributes
5
+ from a GIT server. Supported providers are GitLab and GitHub. Pull requests
6
+ are welcome if you'd like to see additional providers!
7
+
8
+ Note that each provider provides slightly different JSON output. Therefore
9
+ the macro simply extracts the JSON and assigns the libname (using the JSON
10
+ engine).
11
+
12
+ Example usage (eg, to grab latest release version from github):
13
+
14
+ %mp_gitreleaseinfo(GITHUB,sasjs/core,outlib=mylibref)
15
+
16
+ data _null_;
17
+ set mylibref.root;
18
+ putlog TAG_NAME=;
19
+ run;
20
+
21
+ @param [in] provider The GIT provider for the release info. Accepted values:
22
+ @li GITLAB
23
+ @li GITHUB - Tables include root, assets, author, alldata
24
+ @param [in] project The link to the repository. This has different formats
25
+ depending on the vendor:
26
+ @li GITHUB - org/repo, eg sasjs/core
27
+ @li GITLAB - project, eg 1343223
28
+ @param [in] server= (0) If your repo is self-hosted, then provide the domain
29
+ here. Otherwise it will default to the provider domain (eg gitlab.com).
30
+ @param [in] mdebug= (0) Set to 1 to enable DEBUG messages
31
+ @param [out] outlib= (GITREL) The JSON-engine libref to be created, which will
32
+ point at the returned JSON
33
+
34
+ <h4> SAS Macros </h4>
35
+ @li mf_getuniquefileref.sas
36
+
37
+ <h4> Related Files </h4>
38
+ @li mp_gitreleaseinfo.test.sas
39
+
40
+ **/
41
+
42
+ %macro mp_gitreleaseinfo(provider,project,server=0,outlib=GITREL,mdebug=0);
43
+ %local url fref;
44
+
45
+ %let provider=%upcase(&provider);
46
+
47
+ %if &provider=GITHUB %then %do;
48
+ %if "&server"="0" %then %let server=https://api.github.com;
49
+ %let url=&server/repos/&project/releases/latest;
50
+ %end;
51
+ %else %if &provider=GITLAB %then %do;
52
+ %if "&server"="0" %then %let server=https://gitlab.com;
53
+ %let url=&server/api/v4/projects/&project/releases;
54
+ %end;
55
+
56
+ %let fref=%mf_getuniquefileref();
57
+
58
+ proc http method='GET' out=&fref url="&url";
59
+ %if &mdebug=1 %then %do;
60
+ debug level = 3;
61
+ %end;
62
+ run;
63
+
64
+ libname &outlib JSON fileref=&fref;
65
+
66
+ %if &mdebug=1 %then %do;
67
+ data _null_;
68
+ infile &fref;
69
+ input;
70
+ putlog _infile_;
71
+ run;
72
+ %end;
73
+
74
+ %mend mp_gitreleaseinfo;
@@ -0,0 +1,67 @@
1
+ /**
2
+ @file
3
+ @brief Creates a dataset with the output from `GIT_STATUS()`
4
+ @details Uses `git_status()` to fetch the number of changed files, then
5
+ iterates with `git_status_get()`, inserting all attributes into an output
6
+ dataset.
7
+
8
+ Usage:
9
+
10
+ %let dir=%sysfunc(pathname(work))/core;
11
+ %let repo=https://github.com/sasjs/core;
12
+ %put source clone rc=%sysfunc(GITFN_CLONE(&repo,&dir));
13
+ %mf_writefile(&dir/somefile.txt,l1=some content)
14
+ %mf_deletefile(&dir/package.json)
15
+
16
+ %mp_gitstatus(&dir,outds=work.gitstatus)
17
+
18
+ More info on these functions is in this [helpful paper]
19
+ (https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2019/3057-2019.pdf)
20
+ by Danny Zimmerman.
21
+
22
+ @param [in] gitdir The directory containing the GIT repository
23
+ @param [out] outds= (work.git_status) The output dataset to create. Vars:
24
+ @li gitdir $1024 - directory of repo
25
+ @li path $1024 - relative path to the file in the repo
26
+ @li staged $32 - whether the file is staged (TRUE or FALSE)
27
+ @li status $64 - either new, deleted, or modified
28
+ @li cnt - number of files
29
+ @li n - the "nth" file in the list from git_status()
30
+
31
+ @param [in] mdebug= (0) Set to 1 to enable DEBUG messages
32
+
33
+ <h4> Related Files </h4>
34
+ @li mp_gitstatus.test.sas
35
+ @li mp_gitadd.sas
36
+
37
+ **/
38
+
39
+ %macro mp_gitstatus(gitdir,outds=work.mp_gitstatus,mdebug=0);
40
+
41
+ data &outds;
42
+ LENGTH gitdir path $ 1024 STATUS $ 64 STAGED $ 32;
43
+ call missing (of _all_);
44
+ gitdir=symget('gitdir');
45
+ cnt=git_status(trim(gitdir));
46
+ if cnt=-1 then do;
47
+ put "The libgit2 library is unavailable and no Git operations can be used.";
48
+ put "See: https://stackoverflow.com/questions/74082874";
49
+ end;
50
+ else if cnt=-2 then do;
51
+ put "The libgit2 library is available, but the status function failed.";
52
+ put "See the log for details.";
53
+ end;
54
+ else do n=1 to cnt;
55
+ rc=GIT_STATUS_GET(n,gitdir,'PATH',path);
56
+ rc=GIT_STATUS_GET(n,gitdir,'STAGED',staged);
57
+ rc=GIT_STATUS_GET(n,gitdir,'STATUS',status);
58
+ output;
59
+ %if &mdebug=1 %then %do;
60
+ putlog (_all_)(=);
61
+ %end;
62
+ end;
63
+ rc=git_status_free(gitdir);
64
+ drop rc cnt;
65
+ run;
66
+
67
+ %mend mp_gitstatus;
@@ -5,7 +5,7 @@
5
5
  create a hash for each directory also.
6
6
 
7
7
  This makes use of the new `hashing_file()` and `hashing` functions, available
8
- since 9.4m6. Interestingly, these can even be used in pure macro, eg:
8
+ since 9.4m6. Interestingly, those functions can be used in pure macro, eg:
9
9
 
10
10
  %put %sysfunc(hashing_file(md5,/path/to/file.blob,0));
11
11
 
@@ -30,8 +30,9 @@
30
30
  @li If a folder contains other folders, start from the bottom of the tree -
31
31
  the folder hashes cascade upwards so you know immediately if there is a
32
32
  change in a sub/sub directory
33
- @li If the folder has no content (empty) then it is ignored. No hash created.
33
+ @li If a subfolder has no content (empty) then it is ignored. No hash created.
34
34
  @li If the file is empty, it is also ignored / no hash created.
35
+ @li If the target directory (&inloc) is empty, &outds will also be empty
35
36
 
36
37
  <h4> SAS Macros </h4>
37
38
  @li mp_dirlist.sas
@@ -72,7 +73,7 @@
72
73
  iftrue=%str(1=1)
73
74
  )/*/STORE SOURCE*/;
74
75
 
75
- %local curlevel tempds ;
76
+ %local curlevel tempds maxlevel;
76
77
 
77
78
  %if not(%eval(%unquote(&iftrue))) %then %return;
78
79
 
@@ -108,6 +109,7 @@ proc sort data=&outds ;
108
109
  by descending level directory file_path;
109
110
  run;
110
111
 
112
+ %let maxlevel=0;
111
113
  data _null_;
112
114
  set &outds;
113
115
  call symputx('maxlevel',level,'l');
package/package.json CHANGED
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "homepage": "https://github.com/sasjs/utils#readme",
38
38
  "devDependencies": {
39
- "@sasjs/core": "4.41.0",
39
+ "@sasjs/core": "^4.43.1",
40
40
  "@types/cli-table": "0.3.0",
41
41
  "@types/find": "0.2.1",
42
42
  "@types/jest": "27.4.0",
@@ -64,5 +64,5 @@
64
64
  "rimraf": "3.0.2",
65
65
  "valid-url": "1.0.9"
66
66
  },
67
- "version": "2.49.1"
67
+ "version": "2.49.2"
68
68
  }