-
Notifications
You must be signed in to change notification settings - Fork 0
854 lines (781 loc) · 30 KB
/
github-tasks.yml
File metadata and controls
854 lines (781 loc) · 30 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
#############################################################################
# NOTICE!
# You should not modify this file in this repository.
# This Workflow file is tested with workflow found at:
# https://github.com/howijd/.github/blob/main/.github/workflows/github-tasks.yml
#
# And opens self update pull request if base template is updated at:
# https://github.com/howijd/.github/blob/main/workflow-templates/github-tasks.yml
#############################################################################
name: GitHub tasks
on:
issues:
types:
- opened
# - edited
# - deleted
# - transferred
- pinned
- unpinned
- closed
# - reopened
# - assigned
# - unassigned
- labeled
- unlabeled
# - locked
# - unlocked
# - milestoned
# - demilestoned
issue_comment:
types:
- created
# - deleted
# - edited
discussion:
types:
- created
discussion_comment:
types:
- created
pull_request:
types:
- opened
schedule:
- cron: '0 0 * * *' # e.g. 5min */5 * * * * // 'daily'
- cron: '0 09 * * FRI' # 'weekly'
- cron: '0 0 * 10 *' # 'hacktoberfest-running'
- cron: '0 0 1 11 *' # 'hacktoberfest-over'
workflow_dispatch:
inputs:
weeksly-summary:
description: 'Create weekly summary issue yes/no'
default: 'no'
required: true
jobs:
event:
runs-on: ubuntu-latest
steps:
- run: |
echo "event_name: ${{ toJSON(github.event_name) }}"
echo "action: ${{ toJSON(github.event.action) }}"
#############################################################################
# Workflow pipline triggers
# add pipline entrypoint based on event or multiple conditions
#############################################################################
# Issues
issue:
runs-on: ubuntu-latest
if: github.event_name == 'issues'
outputs:
user-issues-total: ${{ steps.set-from-github-graphql.outputs.totalCount }}
zen: ${{ steps.set-from-github-api.outputs.zen }}
issue-is-era: ${{ toJSON(contains(github.event.issue.labels.*.name, 'dao/era')) }}
issue-is-mile: ${{ toJSON(contains(github.event.issue.labels.*.name, 'dao/era')) }}
issue-is-story: ${{ toJSON(contains(github.event.issue.labels.*.name, 'dao/era')) }}
issue-is-task: ${{ toJSON(contains(github.event.issue.labels.*.name, 'dao/era')) }}
steps:
# just print issue payload
- name: issue info
env:
EVENT_PAYLOAD: ${{ toJSON(github.event) }}
run: |
echo "${{ format('issue #{0} - {1}', github.event.issue.number, github.event.issue.html_url) }}"
echo "$EVENT_PAYLOAD"
- name: set from github graphql
id: set-from-github-graphql
uses: actions/github-script@v6
with:
script: |
const user = context.payload.sender.login
const repo = context.payload.repository.name
const owner = context.payload.repository.owner.login
// TOTAL ISSUES
const query = `query($user: String, $owner: String!, $repo: String!) {
repository(owner: $owner, name: $repo) {
issues(filterBy: {createdBy: $user}) {
totalCount
}
}
}`
const res = await github.graphql(query, {
"user": user,
"repo": repo,
"owner": owner,
})
core.info(`user: ${user} has total ${res.repository.issues.totalCount} issues`)
core.setOutput('totalCount', res.repository.issues.totalCount)
- name: set from github api
id: set-from-github-api
uses: actions/github-script@v6
with:
script: |
// RANDOM SENTENCE
// const zen = await github.rest.meta.getZen()
const { data: zen } = await github.request('GET /zen')
core.info(zen)
core.setOutput('zen', zen)
pull-request:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
outputs:
zen: ${{ steps.set-from-github-api.outputs.zen }}
steps:
- name: set from github api
id: set-from-github-api
uses: actions/github-script@v6
with:
script: |
// RANDOM SENTENCE
// const zen = await github.rest.meta.getZen()
const { data: zen } = await github.request('GET /zen')
core.info(zen)
core.setOutput('zen', zen)
issue-comment:
name: Issue comment
runs-on: ubuntu-latest
if: github.event_name == 'issue_comment' && !github.event.issue.pull_request
steps:
- if: github.event.action == 'created'
run: |
echo "${{ github.event.sender.login }} commented on issue #${{ github.event.issue.number }}"
discussion:
runs-on: ubuntu-latest
if: github.event_name == 'discussion'
steps:
- run: exit 0
discussion-comment:
runs-on: ubuntu-latest
if: github.event_name == 'discussion_comment'
steps:
- run: exit 0
# Schedule
schedule:
if: github.event_name == 'schedule'
runs-on: ubuntu-latest
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: echo "$GITHUB_CONTEXT"
# daily schedule
daily:
needs: schedule
if: github.event.schedule == '0 0 * * *'
runs-on: ubuntu-latest
steps:
- if: ${{ contains(toJSON(github.event), 'daily') }}
run: exit 1
# weekly schedule
weekly:
needs: schedule
if: github.event.schedule == '0 09 * * FRI'
runs-on: ubuntu-latest
steps:
- if: ${{ contains(toJSON(github.event), 'weekly') }}
run: exit 1
# weekly schedule
manual:
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- run: exit 0
socials:
needs:
- issue
- issue-comment
- discussion
- discussion-comment
- pull-request
runs-on: ubuntu-latest
if: |
!failure() && !cancelled() && (success('issue-comment') || success('issue') || success('discussion') || success('discussion-comment') || success('pull-request')) &&
(
(github.event_name == 'issue_comment' && github.event.action == 'created') ||
(github.event_name == 'issues' && github.event.action == 'opened') ||
(github.event_name == 'discussion' && github.event.action == 'created') ||
(github.event_name == 'discussion_comment' && github.event.action == 'created') ||
(github.event_name == 'pull_request' && github.event.action == 'opened')
)
outputs:
discord-enabled: ${{ steps.discord.outputs.enabled }}
telegram-enabled: ${{ steps.telegram.outputs.enabled }}
payload: ${{ steps.payload.outputs.result }}
steps:
- id: payload
uses: actions/github-script@v6
with:
script: |
const payload = {
eventName: context.eventName,
author_name: context.actor,
author_avatar_url: '',
author_link: '',
title: '',
link: '',
icon: '',
message: '',
color: '#E88430',
}
let body = ''
switch (payload.eventName) {
case 'issues':
payload.link = context.payload.issue.html_url
payload.icon = context.payload.organization.avatar_url
payload.title = `#${context.payload.issue.number} ${context.payload.issue.title}`
payload.author_name = context.payload.sender.login
payload.author_avatar_url = context.payload.sender.avatar_url
payload.author_link = context.payload.sender.html_url
body = context.payload.issue.body
if (context.payload.issue.labels.length > 0) {
payload.color = `#${context.payload.issue.labels[0].color}`
}
break
case 'pull_request':
payload.link = context.payload.pull_request.html_url
payload.icon = context.payload.organization.avatar_url
payload.title = `#${context.payload.pull_request.number} ${context.payload.pull_request.title}`
payload.author_name = context.payload.sender.login
payload.author_avatar_url = context.payload.sender.avatar_url
payload.author_link = context.payload.sender.html_url
body = context.payload.pull_request.body
if (context.payload.pull_request.labels.length > 0) {
payload.color = `#${context.payload.pull_request.labels[0].color}`
}
break
case 'issue_comment':
payload.link = context.payload.comment.html_url
payload.icon = context.payload.organization.avatar_url
payload.title = `New comment on #${context.payload.issue.number} ${context.payload.issue.title}`
payload.author_name = context.payload.sender.login
payload.author_avatar_url = context.payload.sender.avatar_url
payload.author_link = context.payload.sender.html_url
body = context.payload.comment.body
if (context.payload.issue.labels.length > 0) {
payload.color = `#${context.payload.issue.labels[0].color}`
}
break
case 'discussion':
payload.link = context.payload.discussion.html_url
payload.icon = context.payload.organization.avatar_url
payload.title = `#${context.payload.discussion.number} ${context.payload.discussion.title}`
body = context.payload.discussion.body
payload.author_name = context.payload.sender.login
payload.author_avatar_url = context.payload.sender.avatar_url
payload.author_link = context.payload.sender.html_url
if (context.payload.discussion.labels && context.payload.discussion.labels.length > 0) {
payload.color = `#${context.payload.discussion.labels[0].color}`
}
break
case 'discussion_comment':
payload.link = context.payload.comment.html_url
payload.icon = context.payload.organization.avatar_url
payload.title = `New comment on #${context.payload.discussion.number} ${context.payload.discussion.title}`
payload.author_name = context.payload.sender.login
payload.author_avatar_url = context.payload.sender.avatar_url
payload.author_link = context.payload.sender.html_url
body = context.payload.comment.body
if (context.payload.discussion.labels && context.payload.discussion.labels.length > 0) {
payload.color = `#${context.payload.discussion.labels[0].color}`
}
break
}
payload.message = (body && body.length > 255) ? body.substring(0, 253) : body
return payload
- id: discord
run: echo "::set-output name=enabled::${{ secrets.DISCORD_WEBHOOK_ID != '' }}"
# - id: telegram
# run: echo "::set-output name=enabled::${{ secrets.TELEGRAM_TOKEN != '' }}"
#############################################################################
# Workflow action triggers
# These jobs set outputs for (Workflow actors) use to trigger actual actions
#############################################################################
# compose automatic comment to add
compose-comment:
needs:
- issue
runs-on: ubuntu-latest
if: |
!fromJSON(needs.issue.outputs.issue-is-era) &&
!fromJSON(needs.issue.outputs.issue-is-mile) &&
!fromJSON(needs.issue.outputs.issue-is-story) &&
!fromJSON(needs.issue.outputs.issue-is-task)
outputs:
issue_url: ${{ github.event.issue.html_url }}
issue_comment: ${{ join(steps.*.outputs.value, '') }}
steps:
- name: greeting on first issue
id: greeting-on-first-issue
if: github.event.action == 'opened' && needs.issue.outputs.user-issues-total == 0
uses: mkungla/actions-set-text-output@v1
with:
text: |
👋 Thanks for reporting @${{ github.event.sender.login }}!
This your first issue.
***
- name: greeting for reccuring user
id: greeting-for-reccuring-user
if: github.event.action == 'opened' && needs.issue.outputs.user-issues-total > 0
uses: mkungla/actions-set-text-output@v1
with:
text: |
:boom: Thanks for reporting again @${{ github.event.sender.login }}!
You have opened total **${{ needs.issue.outputs.user-issues-total }}** issues in this repository.
***
- name: comment on empty description
id: comment-on-empty-description
if: github.event.action == 'opened' && !github.event.issue.body
uses: mkungla/actions-set-text-output@v1
with:
text: |
Perhaps edit you issue and add some more detail to issue description?
***
- name: opened issue footer
id: opened-issue-footer
if: github.event.action == 'opened'
uses: mkungla/actions-set-text-output@v1
with:
text: |
Your issue will be reviewed shortly!
${{ needs.issue.outputs.zen }}
This is automated message by **GitHub Actions**
***
# should add remove labels
manage-labels:
needs:
- issue
if: |
!fromJSON(needs.issue.outputs.issue-is-era) &&
!fromJSON(needs.issue.outputs.issue-is-mile) &&
!fromJSON(needs.issue.outputs.issue-is-story) &&
!fromJSON(needs.issue.outputs.issue-is-task)
runs-on: ubuntu-latest
outputs:
add_labels: ${{ join(steps.*.outputs.add_labels, ',') }}
remove_labels: ${{ join(steps.*.outputs.remove_labels, ',') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: on open add labels
id: on-open-add-labels
if: |
github.event.action == 'opened' &&
!contains(github.event.issue.labels.*.name, 'triage')
run: echo "::set-output name=add_labels::triage"
- name: on potential question
id: on-potential-question
if: github.event.action == 'opened' && endsWith(github.event.issue.title, '?')
run: echo "::set-output name=add_labels::question"
- name: on close remove labels
id: on-close-remove-labels
if: github.event.action == 'closed' && contains(github.event.issue.labels.*.name, 'triage')
run: echo "::set-output name=remove_labels::triage"
- name: on pinned add labels
id: on-pinned-add-labels
if: github.event.action == 'pinned' && !contains(github.event.issue.labels.*.name, 'attention')
run: echo "::set-output name=add_labels::attention"
- name: on unpinned remove labels
id: on-unpinned-remove-labels
if: github.event.action == 'unpinned' && contains(github.event.issue.labels.*.name, 'attention')
run: echo "::set-output name=remove_labels::attention"
- name: belongs to feature
if: |
github.event.action == 'opened' &&
(!fromJSON(needs.issue.outputs.issue-is-era) ||
!fromJSON(needs.issue.outputs.issue-is-mile) ||
!fromJSON(needs.issue.outputs.issue-is-story))
id: belongs-to-feature
uses: actions/github-script@v6
with:
script: |
const events = await github.rest.issues.listEventsForTimeline({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
issue_number: context.issue.number,
})
const pi = events.data.filter((item) =>
(item.event === 'cross-referenced' && item.source))
if (pi.length === 0) {
return
}
const belongs = pi.filter((item) => item.source.issue.labels
.filter((label) => label.name.toLowerCase() === 'feature').length > 0)
if (belongs.length > 0) {
core.setOutput('add_labels', 'dao/era')
}
#############################################################################
# Workflow actors
#############################################################################
# comment on issue
create-comment:
# all the jobs which can comment
needs:
- compose-comment
- manage-labels
if: |
always() &&
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled') &&
contains(join(needs.*.outputs.issue_url, ''), 'https://') &&
join(needs.*.outputs.issue_comment, '') != ''
runs-on: ubuntu-latest
env:
issue_url: ${{ join(needs.*.outputs.issue_url, '') }}
issue_comment: ${{ join(needs.*.outputs.issue_comment, '') }}
steps:
# POST copmment
- name: post comment
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh issue comment ${{ env.issue_url }} --body "${{ env.issue_comment }}"
# add labels
add-labels:
needs:
- manage-labels
runs-on: ubuntu-latest
if: join(needs.*.outputs.add_labels, ',') != ''
env:
add_labels: ${{ join(needs.*.outputs.add_labels, ',') }}
steps:
- name: add labels
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh issue edit ${{ github.event.issue.html_url }} --add-label "${{ env.add_labels }}"
# remove labels
remove-labels:
needs:
- manage-labels
runs-on: ubuntu-latest
if: join(needs.*.outputs.remove_labels, ',') != ''
env:
remove_labels: ${{ join(needs.*.outputs.remove_labels, ',') }}
steps:
- name: remove labels
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh issue edit ${{ github.event.issue.html_url }} --remove-label "${{ env.remove_labels }}"
label-commenter:
needs:
- manage-labels
if: github.event.action == 'labeled' || github.event.action == 'unlabeled'
runs-on: ubuntu-latest
steps:
- run: wget -N -P . https://raw.githubusercontent.com/howijd/.github/main/label-commenter-config.yml
- name: Label commenter
uses: peaceiris/actions-label-commenter@v1
with:
config_file: ./label-commenter-config.yml
# add reactions
reaction:
needs:
- issue
runs-on: ubuntu-latest
steps:
- if: github.event.action == 'opened'
uses: actions/github-script@v6
with:
script: |
github.rest.reactions.createForIssue({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
content: 'heart',
})
# check stale issues
stale:
needs:
- daily
- issue-comment
# only run on schedule and issue comment
# also would be nice to skip that if this job was just executed
# e.g. on heated discussion under issue.
if: always() && github.event_name != 'issues'
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v4
with:
days-before-issue-stale: 30
days-before-issue-close: 14
stale-issue-message: 'This issue has no activity for a while. It will be closed if no action is taken in near future'
close-issue-message: 'This issue was closed since there was no activity after it was marked stale.'
stale-issue-label: 'stale'
exempt-issue-labels: 'bug,security,dao/era,dao/era,dao/era'
remove-issue-stale-when-updated: true
labels-to-add-when-unstale: 'triage'
exempt-all-issue-milestones: true
days-before-pr-stale : -1
days-before-pr-close: -1
# hacktoberfest labeler
hacktoberfest:
needs: schedule
if: |
github.event.schedule == '0 0 * 10 *' ||
github.event.schedule == '0 0 1 11 *'
runs-on: ubuntu-latest
steps:
- uses: browniebroke/hacktoberfest-labeler-action@main
continue-on-error: true # topic error - GITHUB_TOKEN do not have permissions
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
# https://github.com/fregante/title-to-labels-action#usage
title-to-labels:
runs-on: ubuntu-latest
needs:
- issue
if: github.event.action == 'opened' || github.event.action == 'edited'
steps:
- uses: fregante/title-to-labels-action@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# should issue be locked
lock:
runs-on: ubuntu-latest
needs:
- issue
if: |
github.event_name == 'issues' &&
github.event.action == 'opened' &&
(fromJSON(needs.issue.outputs.issue-is-era) || fromJSON(needs.issue.outputs.issue-is-mile))
steps:
- run: |
echo "${{ needs.issue.outputs.issue-is-era }}"
echo "${{ needs.issue.outputs.issue-is-mile }}"
- name: set from github api
id: set-from-github-api
uses: actions/github-script@v6
with:
script: |
try {
await github.rest.issues.lock({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
issue_number: context.issue.number,
})
} catch (e) {
core.warning(`Action failed. Could not lock issue with lock reason: ${e}`)
}
handle-question:
runs-on: ubuntu-latest
if: github.event.action == 'labeled' || github.event.action == 'unlabeled'
needs:
- issue
steps:
- uses: dessant/support-requests@v3
with:
support-label: 'support'
issue-comment: |
:wave: @{issue-author}, we use the issue tracker exclusively
for bug reports and feature requests. However, this issue appears
to be a question or support request. Please use our github discussion or
appropriate support channels to get help with the project. Thanks!
Try to ask your question in [Discord](https://discord.io/HowijdNetwork)
close-issue: true
create-week-summary-issue-for-repo:
runs-on: ubuntu-latest
needs:
- manual
if: github.event.inputs.weeksly-summary == 'yes'
steps:
- uses: actions/checkout@v2
- name: set from github graphql
id: set-from-github-graphql
uses: actions/github-script@v6
with:
script: |
const repo = context.payload.repository.name
const owner = context.payload.repository.owner.login
// TOTAL ISSUES
const query = `query ($since: DateTime, $owner: String!, $repo: String!) {
repository(owner: $owner, name: $repo) {
issues(states: [CLOSED], filterBy: {since: $since}, first: 100) {
totalCount
nodes {
url
}
}
pullRequests(states: [MERGED], orderBy: {field: UPDATED_AT, direction: DESC}, first: 100) {
totalCount
nodes {
url
mergedAt
}
}
}
}`
const getmonday = () => {
const now = new Date()
const mon = new Date(now.toUTCString().slice(0, -4))
if (mon.getDay() === 1) {
mon.setDate(mon.getDate() - 1)
}
mon.setDate(mon.getDate() - (mon.getDay() + 6) % 7)
mon.setHours(0, 0, 0, 0)
return mon.toISOString()
}
const monday = getmonday()
const res = await github.graphql(query, {
since: monday,
repo: repo,
owner: owner,
})
let payload = `### ${repo}\n\n`
payload += '#### ISSUES\n\n'
for (let i in res.repository.issues.nodes) {
payload += `- [x] ${res.repository.issues.nodes[i].url}\n`
}
payload += '\n#### PULL REQUESTS\n\n'
for (let i in res.repository.pullRequests.nodes) {
if (new Date(res.repository.pullRequests.nodes[i].mergedAt) < monday) continue
payload += `- [x] ${res.repository.pullRequests.nodes[i].url}\n`
}
core.setOutput('body', payload)
- name: create issue
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
title="WEEK SUMMARY $(date +"%W-%Y")"
gh issue create \
--title "$title" \
--body "${{ steps.set-from-github-graphql.outputs.body }}" \
--label "draft,triage"
collect-week-summary:
runs-on: ubuntu-latest
needs:
- weekly
if: github.repository == 'howijd/howijd.network'
outputs:
issue_body: ${{ steps.set-from-github-graphql.outputs.body }}
steps:
- uses: actions/checkout@v2
- name: set from github graphql
id: set-from-github-graphql
uses: actions/github-script@v6
with:
script: |
const repos = [
'.github',
'howi',
'howijd.network',
'howijd.org',
'howijd.com',
]
const getmonday = () => {
const now = new Date()
const mon = new Date(now.toUTCString().slice(0, -4))
if (mon.getDay() === 1) {
mon.setDate(mon.getDate() - 1)
}
mon.setDate(mon.getDate() - (mon.getDay() + 6) % 7)
mon.setHours(0, 0, 0, 0)
return mon.toISOString()
}
const monday = getmonday()
// TOTAL ISSUES
const getData = async (repo) => {
const owner = 'howijd'
const query = `query ($since: DateTime, $owner: String!, $repo: String!) {
repository(owner: $owner, name: $repo) {
issues(states: [CLOSED], filterBy: {since: $since}, first: 100) {
totalCount
nodes {
url
}
}
pullRequests(states: [MERGED], orderBy: {field: UPDATED_AT, direction: DESC}, first: 100) {
totalCount
nodes {
url
mergedAt
}
}
}
}`
const res = await github.graphql(query, {
since: monday,
repo: repo,
owner: owner,
})
let payload = `### ${repo}\n\n`
payload += '#### ISSUES\n\n'
for (let i in res.repository.issues.nodes) {
payload += `- [x] ${res.repository.issues.nodes[i].url}\n`
}
payload += '\n#### PULL REQUESTS\n\n'
for (let i in res.repository.pullRequests.nodes) {
if (new Date(res.repository.pullRequests.nodes[i].mergedAt) < monday) continue
payload += `- [x] ${res.repository.pullRequests.nodes[i].url}\n`
}
return payload
}
let body = '# PROJECTS\n\n'
for (let i in repos) {
body += await getData(repos[i])
}
core.setOutput('body', body)
create-week-summary-issue:
runs-on: ubuntu-latest
needs: collect-week-summary
steps:
- uses: actions/checkout@v2
- name: create issue
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
title="WEEK SUMMARY $(date +"%W-%Y")"
gh issue create \
--title "$title" \
--body "${{ needs.collect-week-summary.outputs.issue_body }}" \
--label "draft,triage"
# SHARE
discord:
needs: socials
runs-on: ubuntu-latest
if: ${{ !failure() && !cancelled() && needs.socials.outputs.discord-enabled == 'true' }}
steps:
- uses: actions/setup-node@v3
with:
node-version: '16'
- run: npm install discord.js
- env:
webhook_id: ${{ secrets.DISCORD_WEBHOOK_ID }}
webhook_token: ${{ secrets.DISCORD_WEBHOOK_TOKEN }}
payload_str: ${{ needs.socials.outputs.payload }}
run: |
cat >> script.mjs << EOF
import { EmbedBuilder, WebhookClient } from 'discord.js'
const { webhook_id, webhook_token, payload_str } = process.env
const payload = JSON.parse(payload_str)
const webhook = new WebhookClient({ id: webhook_id, token: webhook_token })
const embed = new EmbedBuilder()
.setTitle(payload.title)
.setColor(payload.color)
.setDescription(payload.message)
.setAuthor(
payload.author_name,
payload.author_avatar_url,
payload.author_link,
)
.setFooter('via GitHub', 'https://github.githubassets.com/favicons/favicon.png')
.setURL(payload.link)
webhook.send({
username: '${{ github.event.repository.full_name }}',
avatarURL: '${{ github.event.organization.avatar_url }}',
embeds: [embed],
})
EOF
node ./script.mjs
# telegram:
# needs: socials
# runs-on: ubuntu-latest
# if: ${{ !failure() && !cancelled() && needs.socials.outputs.telegram-enabled == 'true' }}
# steps:
# - uses: appleboy/telegram-action@master
# with:
# to: '-1001195004886'
# token: ${{ secrets.TELEGRAM_TOKEN }}
# format: markdown
# disable_web_page_preview: true
# message: |
# [${{ fromJSON(needs.socials.outputs.payload).title }}](${{ fromJSON(needs.socials.outputs.payload).link }})
# ${{ fromJSON(needs.socials.outputs.payload).message }}"
# by [@${{ fromJSON(needs.socials.outputs.payload).author_name }}](${{ fromJSON(needs.socials.outputs.payload).author_link }})