-
Notifications
You must be signed in to change notification settings - Fork 40
132 lines (118 loc) · 4.48 KB
/
createIssue.yml
File metadata and controls
132 lines (118 loc) · 4.48 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
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
# For more information see: https://o00o.us.to/actions/setup-java#apache-maven-with-a-settings-path
name: CreateIssue
on:
schedule:
- cron: '1 0 1,16 * *'
label:
types: [edited]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Set up Python 3.13
uses: actions/setup-python@v6
with:
python-version: 3.13
- name: Generate github hosts
run: |
python socket_query.py
cat hosts.txt
- name: Close issues of hosts label, return 'invalid' if latest action runs within an hour
uses: actions/github-script@v8
id: check
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
result-encoding: string
script: |
let response = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['host'],
state: 'open'
});
let data = response['data'];
try {
data.forEach(function (issue) {
let id = issue['number'];
let updated_at = new Date(issue['updated_at']);
let time_now = new Date();
let deta = time_now.getTime() - updated_at.getTime();
console.log('deta: ' + deta);
if (deta < 1000 * 60 * 60) {
throw new Error("latest action runs within an hour");
}
github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: id,
state: 'closed'
});
});
return 'valid';
} catch (e) {
return 'invalid';
}
- name: Close issues of out-dated host query
uses: actions/github-script@v8
if: ${{ steps.check.outputs.result == 'valid'}}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
let response = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['host-query'],
state: 'open',
sort: 'updated',
direction: 'asc'
});
let data = response['data'];
data.forEach(function (issue) {
let id = issue['number'];
let is2Deal = true;
let updated_at = new Date(issue['updated_at']);
let time_now = new Date();
let deta = time_now.getTime() - updated_at.getTime();
console.log('deta: ' + deta);
if (deta < 1000 * 60 * 60 * 24 * 5) {
is2Deal = false;
}
if (is2Deal) {
github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: id,
state: 'closed'
});
}
});
- name: Create and lock issue to show hosts
uses: actions/github-script@v8
if: ${{ steps.check.outputs.result == 'valid'}}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const date = new Date();
const year = date.getFullYear().toString();
const month = (date.getMonth() + 1).toString();
const day = date.getDate().toString();
const title = year + '-' + month + '-' + day + ' github hosts';
var fs = require("fs");
fs.readFile("hosts.txt", 'utf-8', (err, data) => {
github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['host'],
title: title,
body: data
}).then((res) =>{
github.rest.issues.lock({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: res.data.number,
lock_reason: "off-topic",
});
});
});