Skip to content

Commit dc6bf12

Browse files
committed
add action
1 parent 6d5a7f0 commit dc6bf12

25 files changed

+12784
-0
lines changed

action/.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist/
2+
lib/
3+
node_modules/
4+
jest.config.js

action/.eslintrc.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"plugins": ["jest", "@typescript-eslint"],
3+
"extends": ["plugin:github/recommended"],
4+
"parser": "@typescript-eslint/parser",
5+
"parserOptions": {
6+
"ecmaVersion": 9,
7+
"sourceType": "module",
8+
"project": "./tsconfig.json"
9+
},
10+
"rules": {
11+
"i18n-text/no-en": "off",
12+
"eslint-comments/no-use": "off",
13+
"import/no-namespace": "off",
14+
"no-unused-vars": "off",
15+
"@typescript-eslint/no-unused-vars": "error",
16+
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
17+
"@typescript-eslint/no-require-imports": "error",
18+
"@typescript-eslint/array-type": "error",
19+
"@typescript-eslint/await-thenable": "error",
20+
"@typescript-eslint/ban-ts-comment": "error",
21+
"camelcase": "off",
22+
"@typescript-eslint/consistent-type-assertions": "error",
23+
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
24+
"@typescript-eslint/func-call-spacing": ["error", "never"],
25+
"@typescript-eslint/no-array-constructor": "error",
26+
"@typescript-eslint/no-empty-interface": "error",
27+
"@typescript-eslint/no-explicit-any": "error",
28+
"@typescript-eslint/no-extraneous-class": "error",
29+
"@typescript-eslint/no-for-in-array": "error",
30+
"@typescript-eslint/no-inferrable-types": "error",
31+
"@typescript-eslint/no-misused-new": "error",
32+
"@typescript-eslint/no-namespace": "error",
33+
"@typescript-eslint/no-non-null-assertion": "warn",
34+
"@typescript-eslint/no-unnecessary-qualifier": "error",
35+
"@typescript-eslint/no-unnecessary-type-assertion": "error",
36+
"@typescript-eslint/no-useless-constructor": "error",
37+
"@typescript-eslint/no-var-requires": "error",
38+
"@typescript-eslint/prefer-for-of": "warn",
39+
"@typescript-eslint/prefer-function-type": "warn",
40+
"@typescript-eslint/prefer-includes": "error",
41+
"@typescript-eslint/prefer-string-starts-ends-with": "error",
42+
"@typescript-eslint/promise-function-async": "error",
43+
"@typescript-eslint/require-array-sort-compare": "error",
44+
"@typescript-eslint/restrict-plus-operands": "error",
45+
"semi": "off",
46+
"@typescript-eslint/semi": ["error", "never"],
47+
"@typescript-eslint/type-annotation-spacing": "error",
48+
"@typescript-eslint/unbound-method": "error"
49+
},
50+
"env": {
51+
"node": true,
52+
"es6": true,
53+
"jest/globals": true
54+
}
55+
}

action/.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/** -diff linguist-generated=true

action/.gitignore

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Dependency directory
2+
node_modules
3+
4+
# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
5+
# Logs
6+
logs
7+
*.log
8+
npm-debug.log*
9+
yarn-debug.log*
10+
yarn-error.log*
11+
lerna-debug.log*
12+
13+
# Diagnostic reports (https://nodejs.org/api/report.html)
14+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
15+
16+
# Runtime data
17+
pids
18+
*.pid
19+
*.seed
20+
*.pid.lock
21+
22+
# Directory for instrumented libs generated by jscoverage/JSCover
23+
lib-cov
24+
25+
# Coverage directory used by tools like istanbul
26+
coverage
27+
*.lcov
28+
29+
# nyc test coverage
30+
.nyc_output
31+
32+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
33+
.grunt
34+
35+
# Bower dependency directory (https://bower.io/)
36+
bower_components
37+
38+
# node-waf configuration
39+
.lock-wscript
40+
41+
# Compiled binary addons (https://nodejs.org/api/addons.html)
42+
build/Release
43+
44+
# Dependency directories
45+
jspm_packages/
46+
47+
# TypeScript v1 declaration files
48+
typings/
49+
50+
# TypeScript cache
51+
*.tsbuildinfo
52+
53+
# Optional npm cache directory
54+
.npm
55+
56+
# Optional eslint cache
57+
.eslintcache
58+
59+
# Optional REPL history
60+
.node_repl_history
61+
62+
# Output of 'npm pack'
63+
*.tgz
64+
65+
# Yarn Integrity file
66+
.yarn-integrity
67+
68+
# dotenv environment variables file
69+
.env
70+
.env.test
71+
72+
# parcel-bundler cache (https://parceljs.org/)
73+
.cache
74+
75+
# next.js build output
76+
.next
77+
78+
# nuxt.js build output
79+
.nuxt
80+
81+
# vuepress build output
82+
.vuepress/dist
83+
84+
# Serverless directories
85+
.serverless/
86+
87+
# FuseBox cache
88+
.fusebox/
89+
90+
# DynamoDB Local files
91+
.dynamodb/
92+
93+
# OS metadata
94+
.DS_Store
95+
Thumbs.db
96+
97+
# Ignore built ts files
98+
__tests__/runner/*
99+
lib/**/*

action/.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist/
2+
lib/
3+
node_modules/

action/.prettierrc.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"printWidth": 80,
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"semi": false,
6+
"singleQuote": true,
7+
"trailingComma": "none",
8+
"bracketSpacing": false,
9+
"arrowParens": "avoid"
10+
}

action/LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2018 GitHub, Inc. and contributors
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.

action/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Generate Badge Action
2+
3+
By [customizing the code template](https://github.com/shuzijun/leetcode-editor/blob/master/doc/CustomCode.md), you can debug, run, and manage the subject code in a project, and you can also save and share these code files. The main function of this action is to cooperate with this project to generate badges for the progress of brushing questions for display, and other data can also be generated and shared based on other data in the future.
4+
5+
## Prerequisites
6+
7+
The premise of using this action is to use the [leetcode-editor](https://github.com/shuzijun/leetcode-editor) plugin, and the files pushed to github include the .idea\leetcode (or Pro version .idea\leetcode-pro) directory in the project directory
8+
9+
## configure
10+
11+
12+
| Configuration item | Explanation | Default value |
13+
| ---------------------- |-------------------------------------------------|----------------------------|
14+
| COMMIT_MESSAGE | Content to be filled in after adding badge push | Update progress badge |
15+
| COMMIT_EMAIL | Committer's email address | github-actions[bot] |
16+
| COMMIT_NAME | Committer name | leetcode-editor-bot |
17+
| BADGES_FILE | Append content file | README.md |
18+
| START_SECTION_FLAG | Start flag of append content area | <\!--START_SECTION_FLAG--> |
19+
| END_SECTION_FLAG | End marker of additional content area | <\!--END_SECTION_FLAG--> |
20+
| STATISTICS_DIRECTORY | Plugin's data file directory | .idea/leetcode/ |
21+
| LEETCODE_SITE | Leetcode's site | leetcode.com |
22+
23+
## Example
24+
25+
````yml
26+
name: CI
27+
28+
on:
29+
push:
30+
branches: [ master ]
31+
pull_request:
32+
branches: [ master ]
33+
34+
workflow_dispatch:
35+
36+
jobs:
37+
build:
38+
runs-on: ubuntu-latest
39+
40+
steps:
41+
- uses: actions/checkout@v3
42+
43+
- uses: ./action/
44+
with:
45+
STATISTICS_DIRECTORY: .idea/leetcode/
46+
LEETCODE_SITE: leetcode.cn
47+
````
48+
49+
## Effect
50+
![Progress](https://img.shields.io/static/v1?logo=leetcode&label=Progress&message=175%2F2643&color=brightgreen) ![Easy](https://img.shields.io/static/v1?logo=leetcode&label=Easy&message=57&color=5CB85C) ![Medium](https://img.shields.io/static/v1?logo=leetcode&label=Medium&message=106&color=F0AD4E) ![Hard](https://img.shields.io/static/v1?logo=leetcode&label=Hard&message=12&color=D9534F)

action/README_ZH.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# 生成勋章行动
2+
3+
通过[自定义代码模板](https://github.com/shuzijun/leetcode-editor/blob/master/doc/CustomCode_ZH.md)可以在一个项目中调试、运行、管理题目代码,同时也可以将这些代码文件进行保存与分享。此行动的主要功能是配合这个项目,生成刷题进度的徽章进行展示,以后也可以根据其他数据生成其他数据进行分享。
4+
5+
## 前提
6+
7+
使用此行动的前提是使用了[leetcode-editor](https://github.com/shuzijun/leetcode-editor)插件,并且推送的到github上的文件包括项目目录下.idea\leetcode(或者Pro版本的.idea\leetcode-pro)目录
8+
9+
## 配置
10+
11+
12+
| 配置项 | 解释 | 默认值 |
13+
| ---------------------- | ---------------------------- |----------------------------|
14+
| COMMIT_MESSAGE | 添加完勋章推送时填写的内容 | Update progress badge |
15+
| COMMIT_EMAIL | 提交人的邮箱 | github-actions[bot] |
16+
| COMMIT_NAME | 提交人姓名 | leetcode-editor-bot |
17+
| BADGES_FILE | 追加内容的文件 | README.md |
18+
| START_SECTION_FLAG | 追加内容区域的开始标识 | <\!--START_SECTION_FLAG--> |
19+
| END_SECTION_FLAG | 追加内容区域的结束标识 | <\!--END_SECTION_FLAG--> |
20+
| STATISTICS_DIRECTORY | 插件的数据文件目录 | .idea/leetcode/ |
21+
| LEETCODE_SITE | 力扣的站点 | leetcode.com |
22+
23+
## 示例
24+
25+
```yml
26+
name: CI
27+
28+
on:
29+
push:
30+
branches: [ master ]
31+
pull_request:
32+
branches: [ master ]
33+
34+
workflow_dispatch:
35+
36+
jobs:
37+
build:
38+
runs-on: ubuntu-latest
39+
40+
steps:
41+
- uses: actions/checkout@v3
42+
43+
- uses: ./action/
44+
with:
45+
STATISTICS_DIRECTORY: .idea/leetcode/
46+
LEETCODE_SITE: leetcode.cn
47+
```
48+
49+
## 效果
50+
![Progress](https://img.shields.io/static/v1?logo=leetcode&label=Progress&message=175%2F2643&color=brightgreen) ![Easy](https://img.shields.io/static/v1?logo=leetcode&label=Easy&message=57&color=5CB85C) ![Medium](https://img.shields.io/static/v1?logo=leetcode&label=Medium&message=106&color=F0AD4E) ![Hard](https://img.shields.io/static/v1?logo=leetcode&label=Hard&message=12&color=D9534F)

action/__tests__/main.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import * as process from 'process'
2+
import * as cp from 'child_process'
3+
import * as path from 'path'
4+
import {expect, test} from '@jest/globals'
5+
import convert from 'xml-js'
6+
7+
8+
// shows how the runner will run a javascript action with env / stdout protocol
9+
test('test runs', () => {
10+
process.env['INPUT_MILLISECONDS'] = '500'
11+
const np = process.execPath
12+
const ip = path.join(__dirname, '..', 'lib', 'main.js')
13+
const options: cp.ExecFileSyncOptions = {
14+
env: process.env
15+
}
16+
console.log(cp.execFileSync(np, [ip], options).toString())
17+
})
18+
19+
test('xml2json',() => {
20+
var xml =
21+
'<?xml version="1.0" encoding="UTF-8"?>\n' +
22+
'<project version="4">\n' +
23+
' <component name="LeetcodeEditorStatistics">\n' +
24+
' <option name="statistics">\n' +
25+
' <map>\n' +
26+
' <entry key="leetcode.cn">\n' +
27+
' <value>\n' +
28+
' <Statistics>\n' +
29+
' <option name="easy" value="57" />\n' +
30+
' <option name="hard" value="12" />\n' +
31+
' <option name="medium" value="106" />\n' +
32+
' <option name="questionTotal" value="2643" />\n' +
33+
' <option name="solvedTotal" value="175" />\n' +
34+
' </Statistics>\n' +
35+
' </value>\n' +
36+
' </entry>\n' +
37+
' </map>\n' +
38+
' </option>\n' +
39+
' </component>\n' +
40+
'</project>';
41+
var result1 = convert.xml2json(xml, {compact: true});
42+
console.log(JSON.parse(result1).project.component.option.map.entry.value.Statistics.option);
43+
})

0 commit comments

Comments
 (0)