@zentered/issue-forms-body-parser 1.2.1 → 1.4.1

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,59 @@
1
+ name: "CodeQL"
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ # The branches below must be a subset of the branches above
8
+ branches: [ main ]
9
+ schedule:
10
+ - cron: '29 21 * * 5'
11
+
12
+ jobs:
13
+ analyze:
14
+ name: Analyze
15
+ runs-on: ubuntu-latest
16
+ permissions:
17
+ actions: read
18
+ contents: read
19
+ security-events: write
20
+
21
+ strategy:
22
+ fail-fast: false
23
+ matrix:
24
+ language: [ 'javascript' ]
25
+ # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
26
+ # Learn more about CodeQL language support at https://git.io/codeql-language-support
27
+
28
+ steps:
29
+ - name: Checkout repository
30
+ uses: actions/checkout@v3
31
+
32
+ # Initializes the CodeQL tools for scanning.
33
+ - name: Initialize CodeQL
34
+ uses: github/codeql-action/init@v2
35
+ with:
36
+ languages: ${{ matrix.language }}
37
+ # If you wish to specify custom queries, you can do so here or in a config file.
38
+ # By default, queries listed here will override any specified in a config file.
39
+ # Prefix the list here with "+" to use these queries and those in the config file.
40
+ # queries: ./path/to/local/query, your-org/your-repo/queries@main
41
+
42
+ # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
43
+ # If this step fails, then you should remove it and run the build manually (see below)
44
+ - name: Autobuild
45
+ uses: github/codeql-action/autobuild@v2
46
+
47
+ # ℹ️ Command-line programs to run using the OS shell.
48
+ # 📚 https://git.io/JvXDl
49
+
50
+ # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
51
+ # and modify them (or add more) to build your code if your project
52
+ # uses a compiled language
53
+
54
+ #- run: |
55
+ # make bootstrap
56
+ # make release
57
+
58
+ - name: Perform CodeQL Analysis
59
+ uses: github/codeql-action/analyze@v2
package/README.md CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  ![Test](https://github.com/zentered/issue-forms-body-parser/workflows/Test/badge.svg)
4
4
  ![Release](https://github.com/zentered/issue-forms-body-parser/workflows/Publish/badge.svg)
5
- ![Semantic Release](https://github.com/zentered/issue-forms-body-parser/workflows/Semantic%20Release/badge.svg)
6
5
  [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
7
6
  [![zentered.co](https://img.shields.io/badge/%3E-zentered.co-blue.svg?style=flat)](https://zentered.co)
8
7
 
@@ -21,9 +20,9 @@ and provides structured data to create calendar entries (ie `.ics` files for
21
20
  [calendar subscriptions with GitEvents](https://github.com/gitevents/ics)),
22
21
  calling 3rd party APIs, etc.
23
22
 
24
- \_Inspired by:
23
+ _Inspired by:
25
24
  [Peter Murray's Issue Forms Body Parser](https://github.com/peter-murray/issue-forms-body-parser)
26
- with valuable feedback from [Steffen](https://gist.github.com/steffen)\_
25
+ with valuable feedback from [Steffen](https://gist.github.com/steffen)_
27
26
 
28
27
  ## Features
29
28
 
@@ -62,25 +61,30 @@ Cafe Nero Finikoudes, Larnaka
62
61
  to structured, usable data:
63
62
 
64
63
  ```json
65
- [
66
- {
67
- "id": "event-description",
64
+ {
65
+ "event-description": {
66
+ "order": 0,
68
67
  "title": "Event Description",
69
- "text": "Let's meet for coffee and chat about tech, coding, Cyprus and the newly formed\nCDC (Cyprus Developer Community).\n"
68
+ "text": "Let's meet for coffee and chat about tech, coding, Cyprus and the newly formed\nCDC (Cyprus Developer Community)."
70
69
  },
71
- {
72
- "id": "location",
70
+ "location": {
71
+ "order": 1,
73
72
  "title": "Location",
74
- "text": "Cafe Nero Finikoudes, Larnaka\n"
73
+ "text": "Cafe Nero Finikoudes, Larnaka"
75
74
  },
76
- {
77
- "id": "date",
75
+ "date": {
76
+ "order": 2,
78
77
  "title": "Date",
79
- "text": "11.03.2022\n",
78
+ "text": "11.03.2022",
80
79
  "date": "2022-03-11"
81
80
  },
82
- { "id": "time", "title": "Time", "text": "16:00\n", "time": "16:00" }
83
- ]
81
+ "time": {
82
+ "order": 3,
83
+ "title": "Time",
84
+ "text": "16:00",
85
+ "time": "16:00"
86
+ }
87
+ }
84
88
  ```
85
89
 
86
90
  See more examples in [md test cases](./test/test-issue-1.md) and
@@ -88,11 +92,15 @@ See more examples in [md test cases](./test/test-issue-1.md) and
88
92
 
89
93
  ### Parsers
90
94
 
91
- - `date`: checks if the value matches a [common date format](https://github.com/zentered/issue-forms-body-parser/blob/main/src/parse.js#L14) and returns a formatted `date` field (in UTC).
92
- - `time`: checks if the value matches a [common time format](https://github.com/zentered/issue-forms-body-parser/blob/main/src/parse.js#L24) and returns a formatted `time` field.
95
+ - `date`: checks if the value matches a
96
+ [common date format](https://github.com/zentered/issue-forms-body-parser/blob/main/src/parsers/date.js#L7)
97
+ and returns a formatted `date` field (in UTC).
98
+ - `time`: checks if the value matches a
99
+ [common time format](https://github.com/zentered/issue-forms-body-parser/blob/main/src/parsers/time.js#L7)
100
+ and returns a formatted `time` field.
93
101
  - `lists`: automatically returns lists as arrays
94
- - `duration`: currently only the format `XXhYYm` is supported as duration, ie. `1h30m` returns a `duration` object with `hours` and `minutes`.
95
-
102
+ - `duration`: currently only the format `XXhYYm` is supported as duration, ie.
103
+ `1h30m` returns a `duration` object with `hours` and `minutes`.
96
104
 
97
105
  ## Installation & Usage
98
106
 
@@ -109,7 +117,7 @@ jobs:
109
117
  steps:
110
118
  - name: Issue Forms Body Parser
111
119
  id: parse
112
- uses: zentered/issue-forms-body-parser@v1.2.0
120
+ uses: zentered/issue-forms-body-parser@v2.0.0
113
121
  - run: echo "${{ JSON.stringify(steps.parse.outputs.data) }}"
114
122
  ```
115
123
 
package/dist/index.js CHANGED
@@ -51787,8 +51787,6 @@ function remarkStringify(options) {
51787
51787
 
51788
51788
  /* harmony default export */ const remark_stringify = (remarkStringify);
51789
51789
 
51790
- // EXTERNAL MODULE: ./node_modules/date-fns/index.js
51791
- var date_fns = __nccwpck_require__(3314);
51792
51790
  ;// CONCATENATED MODULE: ./node_modules/strip-final-newline/index.js
51793
51791
  function stripFinalNewline(input) {
51794
51792
  const LF = typeof input === 'string' ? '\n' : '\n'.charCodeAt();
@@ -51805,6 +51803,8 @@ function stripFinalNewline(input) {
51805
51803
  return input;
51806
51804
  }
51807
51805
 
51806
+ // EXTERNAL MODULE: ./node_modules/date-fns/index.js
51807
+ var date_fns = __nccwpck_require__(3314);
51808
51808
  // EXTERNAL MODULE: ./node_modules/date-fns/_lib/cloneObject/index.js
51809
51809
  var cloneObject = __nccwpck_require__(7934);
51810
51810
  // EXTERNAL MODULE: ./node_modules/date-fns/_lib/toInteger/index.js
@@ -52582,6 +52582,38 @@ function zonedTimeToUtc(date, timeZone, options) {
52582
52582
  return new Date(utc + offsetMilliseconds)
52583
52583
  }
52584
52584
 
52585
+ ;// CONCATENATED MODULE: ./src/parsers/date.js
52586
+
52587
+
52588
+ ;
52589
+
52590
+
52591
+ const loc = 'UTC'
52592
+ const commonDateFormats = [
52593
+ 'yyyy-MM-dd',
52594
+ 'dd/MM/yyyy',
52595
+ 'dd/MM/yy',
52596
+ 'dd-MM-yyyy',
52597
+ 'dd-MM-yy',
52598
+ 'dd.MM.yyyy',
52599
+ 'dd.MM.yy'
52600
+ ]
52601
+
52602
+ function date_parseDate(text) {
52603
+ const match = commonDateFormats.map((format) => {
52604
+ return (0,date_fns.isMatch)(text, format)
52605
+ })
52606
+ if (match.indexOf(true) > -1) {
52607
+ const date = zonedTimeToUtc(
52608
+ (0,date_fns.parse)(text, commonDateFormats[match.indexOf(true)], new Date()),
52609
+ loc
52610
+ ).toJSON()
52611
+ return date.split('T')[0]
52612
+ } else {
52613
+ return null
52614
+ }
52615
+ }
52616
+
52585
52617
  // EXTERNAL MODULE: ./node_modules/date-fns/format/index.js
52586
52618
  var format = __nccwpck_require__(2168);
52587
52619
  ;// CONCATENATED MODULE: ./node_modules/date-fns-tz/esm/_lib/tzIntlTimeZoneName/index.js
@@ -53194,75 +53226,65 @@ function formatInTimeZone(date, timeZone, formatStr, options) {
53194
53226
  return format_format(utcToZonedTime(date, timeZone), formatStr, extendedOptions)
53195
53227
  }
53196
53228
 
53197
- ;// CONCATENATED MODULE: ./src/parse.js
53229
+ ;// CONCATENATED MODULE: ./src/parsers/time.js
53198
53230
 
53199
53231
 
53200
53232
  ;
53201
53233
 
53202
53234
 
53235
+ const time_loc = 'UTC'
53236
+ const commonTimeFormats = ['HH:mm', 'HH.mm', 'hh:mm a', 'hh:mm A']
53203
53237
 
53238
+ function time_parseTime(text) {
53239
+ const match = commonTimeFormats.map((format) => {
53240
+ return (0,date_fns.isMatch)(text, format)
53241
+ })
53242
+ if (match.indexOf(true) > -1) {
53243
+ const time = zonedTimeToUtc(
53244
+ (0,date_fns.parse)(text, commonTimeFormats[match.indexOf(true)], new Date()),
53245
+ time_loc
53246
+ )
53247
+ return formatInTimeZone(time, time_loc, 'HH:mm')
53248
+ } else {
53249
+ return null
53250
+ }
53251
+ }
53204
53252
 
53253
+ ;// CONCATENATED MODULE: ./src/parsers/duration.js
53205
53254
 
53206
53255
 
53207
-
53208
- // if the system time is not UTC, we need to convert it to UTC
53209
-
53210
- const loc = 'UTC'
53211
-
53212
- const commonDateFormats = [
53213
- 'yyyy-MM-dd',
53214
- 'dd/MM/yyyy',
53215
- 'dd/MM/yy',
53216
- 'dd-MM-yyyy',
53217
- 'dd-MM-yy',
53218
- 'dd.MM.yyyy',
53219
- 'dd.MM.yy'
53220
- ]
53221
-
53222
- const commonTimeFormats = ['HH:mm', 'HH.mm', 'hh:mm a', 'hh:mm A']
53223
-
53224
53256
  function parseDuration(text) {
53257
+ let matched = false
53225
53258
  const duration = {
53226
53259
  hours: 0,
53227
53260
  minutes: 0
53228
53261
  }
53229
53262
 
53230
- const pieces = text.replace('m', '').split('h')
53231
- duration.hours = parseInt(pieces[0]) ? parseInt(pieces[0]) : 0
53232
- duration.minutes = parseInt(pieces[1]) ? parseInt(pieces[1]) : 0
53233
- return duration
53234
- }
53263
+ const hoursAndMinutes = new RegExp(/([0-9]+)h([0-9]+)m/)
53264
+ const hours = new RegExp(/([0-9]+)h/)
53235
53265
 
53236
- function parse_parseDate(text) {
53237
- const match = commonDateFormats.map((format) => {
53238
- return (0,date_fns.isMatch)(text, format)
53239
- })
53240
- if (match.indexOf(true) > -1) {
53241
- const date = zonedTimeToUtc(
53242
- (0,date_fns.parse)(text, commonDateFormats[match.indexOf(true)], new Date()),
53243
- loc
53244
- ).toJSON()
53245
- return date.split('T')[0]
53246
- } else {
53247
- return null
53266
+ if (text.match(hoursAndMinutes)) {
53267
+ matched = true
53268
+ const [, h, m] = text.match(hoursAndMinutes)
53269
+ duration.hours = parseInt(h)
53270
+ duration.minutes = parseInt(m)
53271
+ } else if (text.match(hours)) {
53272
+ matched = true
53273
+ const [, h] = text.match(hours)
53274
+ duration.hours = parseInt(h)
53275
+ duration.minutes = 0
53248
53276
  }
53249
- }
53250
53277
 
53251
- function parse_parseTime(text) {
53252
- const match = commonTimeFormats.map((format) => {
53253
- return (0,date_fns.isMatch)(text, format)
53254
- })
53255
- if (match.indexOf(true) > -1) {
53256
- const time = zonedTimeToUtc(
53257
- (0,date_fns.parse)(text, commonTimeFormats[match.indexOf(true)], new Date()),
53258
- loc
53259
- )
53260
- return formatInTimeZone(time, loc, 'HH:mm')
53278
+ if (matched) {
53279
+ return duration
53261
53280
  } else {
53262
53281
  return null
53263
53282
  }
53264
53283
  }
53265
53284
 
53285
+ ;// CONCATENATED MODULE: ./src/parsers/list.js
53286
+
53287
+
53266
53288
  function parseList(list) {
53267
53289
  return list.children
53268
53290
  .map((item) => {
@@ -53293,55 +53315,113 @@ function parseList(list) {
53293
53315
  .filter((x) => !!x)
53294
53316
  }
53295
53317
 
53318
+ ;// CONCATENATED MODULE: ./src/parsers/index.js
53319
+
53320
+
53321
+ ;
53322
+
53323
+
53324
+
53325
+
53326
+ const parsers_parseDate = date_parseDate
53327
+ const parsers_parseTime = time_parseTime
53328
+ const parsers_parseDuration = parseDuration
53329
+ const parsers_parseList = parseList
53330
+
53331
+ ;// CONCATENATED MODULE: ./src/parse.js
53332
+
53333
+
53334
+ ;
53335
+
53336
+
53337
+
53338
+
53339
+
53340
+
53341
+
53342
+
53296
53343
  async function parseMD(body) {
53297
53344
  const tokens = await unified().use(remark_parse).use(remarkGfm).parse(body)
53298
53345
  if (!tokens) {
53299
53346
  return []
53300
53347
  }
53301
53348
 
53302
- const r = []
53303
- for (let idx = 0; idx < tokens.children.length; idx = idx + 2) {
53304
- const current = tokens.children[idx]
53305
- const hasNext = idx + 1 < tokens.children.length
53349
+ const structuredResponse = {}
53350
+ let currentHeading = null
53351
+ for (const token of tokens.children) {
53352
+ const text = await unified()
53353
+ .use(remarkGfm)
53354
+ .use(remark_stringify)
53355
+ .stringify(token)
53356
+ const cleanText = stripFinalNewline(text)
53357
+
53358
+ // issue forms uses h3 as a heading
53359
+ if (token.type === 'heading' && token.depth === 3) {
53360
+ currentHeading = slugify(token.children[0].value)
53361
+ structuredResponse[currentHeading] = {
53362
+ title: token.children[0].value,
53363
+ content: []
53364
+ }
53365
+ } else if (token.type === 'paragraph' && currentHeading) {
53366
+ const obj = structuredResponse[currentHeading]
53367
+
53368
+ const date = parsers_parseDate(cleanText)
53369
+ const time = parsers_parseTime(cleanText)
53370
+ const duration = parsers_parseDuration(cleanText)
53306
53371
 
53307
- if (current.type === 'heading') {
53308
- // issue-form answers start with a h3 heading, ignore everything else
53309
- const obj = {
53310
- id: slugify(current.children[0].value),
53311
- title: current.children[0].value
53372
+ if (date) {
53373
+ obj.date = date
53312
53374
  }
53313
- if (hasNext) {
53314
- const next = tokens.children[idx + 1]
53315
- if (next.type === 'list') {
53316
- obj.list = parseList(next).flat()
53317
- }
53318
- const text = await unified()
53319
- .use(remarkGfm)
53320
- .use(remark_stringify)
53321
- .stringify(next)
53322
- obj.text = stripFinalNewline(text)
53323
- const date = parse_parseDate(obj.text)
53324
- const time = parse_parseTime(obj.text)
53325
- if (date) {
53326
- obj.date = date
53327
- }
53328
- if (time) {
53329
- obj.time = time
53330
- }
53331
- if (obj.id === 'duration') {
53332
- obj.duration = parseDuration(obj.text)
53333
- }
53375
+
53376
+ if (time) {
53377
+ obj.time = time
53378
+ }
53379
+
53380
+ if (duration) {
53381
+ obj.duration = duration
53334
53382
  }
53335
- r.push(obj)
53383
+
53384
+ obj.content.push(cleanText)
53385
+ } else if (token.type === 'list') {
53386
+ const obj = structuredResponse[currentHeading]
53387
+ obj.text = cleanText
53388
+ obj.list = parsers_parseList(token).flat()
53389
+ } else if (token.type === 'html') {
53390
+ const obj = structuredResponse[currentHeading]
53391
+ obj.content.push(token.html)
53392
+ } else if (token.type === 'code') {
53393
+ const obj = structuredResponse[currentHeading]
53394
+ obj.lang = token.lang
53395
+ obj.text = cleanText
53396
+ } else if (token.type === 'heading' && token.depth > 3) {
53397
+ const obj = structuredResponse[currentHeading]
53398
+ obj.content.push(token.children[0].value)
53399
+ } else {
53400
+ console.log('unhandled token type')
53401
+ console.log(token)
53336
53402
  }
53337
53403
  }
53338
53404
 
53339
- return r
53405
+ for (const key in structuredResponse) {
53406
+ const token = structuredResponse[key]
53407
+ const content = token.content.filter(Boolean)
53408
+ if (content && content.length > 0) {
53409
+ if (content.length === 1) {
53410
+ token.text = content[0]
53411
+ }
53412
+ token.text = content.join('\n\n')
53413
+ }
53414
+ token.content = content
53415
+ }
53416
+
53417
+ return structuredResponse
53340
53418
  }
53341
53419
 
53342
53420
  ;// CONCATENATED MODULE: ./src/index.js
53343
53421
 
53344
53422
 
53423
+ ;
53424
+
53345
53425
 
53346
53426
 
53347
53427
  async function run() {
package/dist/parse.cjs ADDED
@@ -0,0 +1,2 @@
1
+ var e=require("@actions/github"),t=require("@actions/core"),n=require("unified"),r=require("remark-parse"),i=require("remark-gfm"),o=require("@sindresorhus/slugify"),u=require("remark-stringify"),a=require("strip-final-newline"),f=require("date-fns"),c=require("date-fns-tz/esm");function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var d=/*#__PURE__*/l(e),s=/*#__PURE__*/l(t),h=/*#__PURE__*/l(r),v=/*#__PURE__*/l(i),y=/*#__PURE__*/l(o),m=/*#__PURE__*/l(u),p=/*#__PURE__*/l(a);function g(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var b=["yyyy-MM-dd","dd/MM/yyyy","dd/MM/yy","dd-MM-yyyy","dd-MM-yy","dd.MM.yyyy","dd.MM.yy"],M=["HH:mm","HH.mm","hh:mm a","hh:mm A"],x=function e(t){return t.children.map(function(n){var r={};return"list"===n.type?e(t):"listItem"===n.type?(r.checked=n.checked,n.children.map(function(e){if("paragraph"===e.type)return r.text=e.children.map(function(e){return"link"===e.type?e.children[0].value:e.value}).filter(function(e){return!!e}).join(""),r}).filter(function(e){return!!e})):void 0}).filter(function(e){return!!e})};function w(e,t,n){if(!e.s){if(n instanceof T){if(!n.s)return void(n.o=w.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(w.bind(null,e,t),w.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}const T=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){const r=new e,i=this.s;if(i){const e=1&i?t:n;if(e){try{w(r,1,e(this.v))}catch(e){w(r,2,e)}return r}return this}return this.o=function(e){try{const i=e.v;1&e.s?w(r,1,t?t(i):i):n?w(r,1,n(i)):w(r,2,i)}catch(e){w(r,2,e)}},r},e}();function q(e){return e instanceof T&&1&e.s}!function(){try{s.default.info("Parsing issue body ...");var e=function(e,t){try{var r=Promise.resolve(function(e){try{var t,r,i,o,u,a,l,d,s,k,j,I,O;return Promise.resolve(n.unified().use(h.default).use(v.default).parse(e)).then(function(e){function h(){for(j in A)(O=(I=A[j]).content.filter(Boolean))&&O.length>0&&(1===O.length&&(I.text=O[0]),I.text=O.join("\n\n")),I.content=O;return A}if(!e)return[];var A={},P=null;t=function(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return g(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?g(e,t):void 0}}(e))){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(e.children);var H=function(e,t,n){for(var r;;){var i=e();if(q(i)&&(i=i.v),!i)return o;if(i.then){r=0;break}var o=n();if(o&&o.then){if(!q(o)){r=1;break}o=o.s}}var u=new T,a=w.bind(null,u,2);return(0===r?i.then(c):1===r?o.then(f):(void 0).then(function(){(i=e())?i.then?i.then(c).then(void 0,a):c(i):w(u,1,o)})).then(void 0,a),u;function f(t){o=t;do{if(!(i=e())||q(i)&&!i.v)return void w(u,1,o);if(i.then)return void i.then(c).then(void 0,a);q(o=n())&&(o=o.v)}while(!o||!o.then);o.then(f).then(void 0,a)}function c(e){e?(o=n())&&o.then?o.then(f).then(void 0,a):f(o):w(u,1,o)}}(function(){return!(r=t()).done},0,function(){return i=r.value,Promise.resolve(n.unified().use(v.default).use(m.default).stringify(i)).then(function(e){var t,n;o=p.default(e),"heading"===i.type&&3===i.depth?(P=y.default(i.children[0].value),A[P]={title:i.children[0].value,content:[]}):"paragraph"===i.type&&P?(u=A[P],t=o,n=b.map(function(e){return f.isMatch(t,e)}),a=n.indexOf(!0)>-1?c.zonedTimeToUtc(f.parse(t,b[n.indexOf(!0)],new Date),"UTC").toJSON().split("T")[0]:null,l=function(e){var t=M.map(function(t){return f.isMatch(e,t)});if(t.indexOf(!0)>-1){var n=c.zonedTimeToUtc(f.parse(e,M[t.indexOf(!0)],new Date),"UTC");return c.formatInTimeZone(n,"UTC","HH:mm")}return null}(o),d=function(e){var t=!1,n={hours:0,minutes:0},r=new RegExp(/([0-9]+)h([0-9]+)m/),i=new RegExp(/([0-9]+)h/);if(e.match(r)){t=!0;var o=e.match(r),u=o[2];n.hours=parseInt(o[1]),n.minutes=parseInt(u)}else if(e.match(i)){t=!0;var a=e.match(i);n.hours=parseInt(a[1]),n.minutes=0}return t?n:null}(o),a&&(u.date=a),l&&(u.time=l),d&&(u.duration=d),u.content.push(o)):"list"===i.type?((s=A[P]).text=o,s.list=x(i).flat()):"html"===i.type?A[P].content.push(i.html):"code"===i.type?((k=A[P]).lang=i.lang,k.text=o):"heading"===i.type&&i.depth>3?A[P].content.push(i.children[0].value):(console.log("unhandled token type"),console.log(i))})});return H&&H.then?H.then(h):h()})}catch(e){return Promise.reject(e)}}(d.default.context.payload.issue.body)).then(function(e){void 0!==e?s.default.setOutput("data",e):s.default.setFailed("There was no valid payload found in the issue.")})}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}(0,function(e){s.default.setFailed(e)});Promise.resolve(e&&e.then?e.then(function(){}):void 0)}catch(e){return Promise.reject(e)}}();
2
+ //# sourceMappingURL=parse.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.cjs","sources":["../src/parsers/date.js","../src/parsers/time.js","../src/parsers/index.js","../src/parsers/list.js","../src/parse.js","../src/index.js","../src/parsers/duration.js"],"sourcesContent":["'use strict'\n\nimport { parse, isMatch } from 'date-fns'\nimport { zonedTimeToUtc } from 'date-fns-tz/esm'\n\nconst loc = 'UTC'\nconst commonDateFormats = [\n 'yyyy-MM-dd',\n 'dd/MM/yyyy',\n 'dd/MM/yy',\n 'dd-MM-yyyy',\n 'dd-MM-yy',\n 'dd.MM.yyyy',\n 'dd.MM.yy'\n]\n\nexport default function parseDate(text) {\n const match = commonDateFormats.map((format) => {\n return isMatch(text, format)\n })\n if (match.indexOf(true) > -1) {\n const date = zonedTimeToUtc(\n parse(text, commonDateFormats[match.indexOf(true)], new Date()),\n loc\n ).toJSON()\n return date.split('T')[0]\n } else {\n return null\n }\n}\n","'use strict'\n\nimport { parse, isMatch } from 'date-fns'\nimport { zonedTimeToUtc, formatInTimeZone } from 'date-fns-tz/esm'\n\nconst loc = 'UTC'\nconst commonTimeFormats = ['HH:mm', 'HH.mm', 'hh:mm a', 'hh:mm A']\n\nexport default function parseTime(text) {\n const match = commonTimeFormats.map((format) => {\n return isMatch(text, format)\n })\n if (match.indexOf(true) > -1) {\n const time = zonedTimeToUtc(\n parse(text, commonTimeFormats[match.indexOf(true)], new Date()),\n loc\n )\n return formatInTimeZone(time, loc, 'HH:mm')\n } else {\n return null\n }\n}\n","'use strict'\n\nimport date from './date.js'\nimport time from './time.js'\nimport duration from './duration.js'\nimport list from './list.js'\n\nexport const parseDate = date\nexport const parseTime = time\nexport const parseDuration = duration\nexport const parseList = list\n","'use strict'\n\nexport default function parseList(list) {\n return list.children\n .map((item) => {\n const listItem = {}\n if (item.type === 'list') {\n return parseList(list)\n } else if (item.type === 'listItem') {\n listItem.checked = item.checked\n return item.children\n .map((child) => {\n if (child.type === 'paragraph') {\n listItem.text = child.children\n .map((c) => {\n if (c.type === 'link') {\n return c.children[0].value\n } else {\n return c.value\n }\n })\n .filter((x) => !!x)\n .join('')\n return listItem\n }\n })\n .filter((x) => !!x)\n }\n })\n .filter((x) => !!x)\n}\n","'use strict'\n\nimport { unified } from 'unified'\nimport remarkParse from 'remark-parse'\nimport remarkGfm from 'remark-gfm'\nimport slugify from '@sindresorhus/slugify'\nimport remarkStringify from 'remark-stringify'\nimport stripFinalNewline from 'strip-final-newline'\n\nimport {\n parseDate,\n parseTime,\n parseDuration,\n parseList\n} from './parsers/index.js'\n\nexport default async function parseMD(body) {\n const tokens = await unified().use(remarkParse).use(remarkGfm).parse(body)\n if (!tokens) {\n return []\n }\n\n const structuredResponse = {}\n let currentHeading = null\n for (const token of tokens.children) {\n const text = await unified()\n .use(remarkGfm)\n .use(remarkStringify)\n .stringify(token)\n const cleanText = stripFinalNewline(text)\n\n // issue forms uses h3 as a heading\n if (token.type === 'heading' && token.depth === 3) {\n currentHeading = slugify(token.children[0].value)\n structuredResponse[currentHeading] = {\n title: token.children[0].value,\n content: []\n }\n } else if (token.type === 'paragraph' && currentHeading) {\n const obj = structuredResponse[currentHeading]\n\n const date = parseDate(cleanText)\n const time = parseTime(cleanText)\n const duration = parseDuration(cleanText)\n\n if (date) {\n obj.date = date\n }\n\n if (time) {\n obj.time = time\n }\n\n if (duration) {\n obj.duration = duration\n }\n\n obj.content.push(cleanText)\n } else if (token.type === 'list') {\n const obj = structuredResponse[currentHeading]\n obj.text = cleanText\n obj.list = parseList(token).flat()\n } else if (token.type === 'html') {\n const obj = structuredResponse[currentHeading]\n obj.content.push(token.html)\n } else if (token.type === 'code') {\n const obj = structuredResponse[currentHeading]\n obj.lang = token.lang\n obj.text = cleanText\n } else if (token.type === 'heading' && token.depth > 3) {\n const obj = structuredResponse[currentHeading]\n obj.content.push(token.children[0].value)\n } else {\n console.log('unhandled token type')\n console.log(token)\n }\n }\n\n for (const key in structuredResponse) {\n const token = structuredResponse[key]\n const content = token.content.filter(Boolean)\n if (content && content.length > 0) {\n if (content.length === 1) {\n token.text = content[0]\n }\n token.text = content.join('\\n\\n')\n }\n token.content = content\n }\n\n return structuredResponse\n}\n","'use strict'\n\nimport github from '@actions/github'\nimport core from '@actions/core'\nimport parse from './parse.js'\n\nasync function run() {\n core.info('Parsing issue body ...')\n\n try {\n const parsedContent = await parse(github.context.payload.issue.body)\n\n if (parsedContent !== undefined) {\n core.setOutput('data', parsedContent)\n } else {\n core.setFailed(`There was no valid payload found in the issue.`)\n }\n } catch (err) {\n core.setFailed(err)\n }\n}\n\nrun()\n","'use strict'\n\nexport default function parseDuration(text) {\n let matched = false\n const duration = {\n hours: 0,\n minutes: 0\n }\n\n const hoursAndMinutes = new RegExp(/([0-9]+)h([0-9]+)m/)\n const hours = new RegExp(/([0-9]+)h/)\n\n if (text.match(hoursAndMinutes)) {\n matched = true\n const [, h, m] = text.match(hoursAndMinutes)\n duration.hours = parseInt(h)\n duration.minutes = parseInt(m)\n } else if (text.match(hours)) {\n matched = true\n const [, h] = text.match(hours)\n duration.hours = parseInt(h)\n duration.minutes = 0\n }\n\n if (matched) {\n return duration\n } else {\n return null\n }\n}\n"],"names":["commonDateFormats","commonTimeFormats","parseList","list","children","map","item","listItem","type","checked","child","text","c","value","filter","x","join","_settle","pact","state","s","_Pact","o","bind","v","then","observer","prototype","onFulfilled","onRejected","result","this","callback","e","_this","thenable","core","info","_temp2","body","recover","parse","token","cleanText","obj","date","time","duration","key","content","unified","use","remarkParse","remarkGfm","tokens","structuredResponse","Boolean","length","currentHeading","_iterator","test","update","stage","shouldContinue","_isSettledPact","reject","_resumeAfterTest","_resumeAfterBody","updateValue","remarkStringify","stringify","match","stripFinalNewline","depth","slugify","title","format","isMatch","indexOf","zonedTimeToUtc","Date","toJSON","split","parseTime","formatInTimeZone","matched","hours","minutes","hoursAndMinutes","RegExp","_text$match","m","parseInt","parseDuration","push","flat","html","lang","console","log","_temp","github","context","payload","issue","parsedContent","undefined","setOutput","setFailed","_catch","err","Promise","resolve","run"],"mappings":"0lBAKA,IACMA,EAAoB,CACxB,aACA,aACA,WACA,aACA,WACA,aACA,YCPIC,EAAoB,CAAC,QAAS,QAAS,UAAW,WCI3CC,ECRWA,SAAAA,EAAUC,GAChC,OAAOA,EAAKC,SACTC,IAAI,SAACC,GACJ,IAAMC,EAAW,GACjB,MAAkB,SAAdD,EAAKE,KACAN,EAAUC,GACM,aAAdG,EAAKE,MACdD,EAASE,QAAUH,EAAKG,QACjBH,EAAKF,SACTC,IAAI,SAACK,GACJ,GAAmB,cAAfA,EAAMF,KAWR,OAVAD,EAASI,KAAOD,EAAMN,SACnBC,IAAI,SAACO,GACJ,MAAe,SAAXA,EAAEJ,KACGI,EAAER,SAAS,GAAGS,MAEdD,EAAEC,QAGZC,OAAO,SAACC,GAAD,QAASA,IAChBC,KAAK,IAC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