├── package.json
├── .gitignore
├── .github
└── workflows
│ └── auto-update.yml
├── LICENSE
├── main.js
└── README.md
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": {
3 | "@actions/github": "^4.0.0",
4 | "@octokit/rest": "^18.2.0",
5 | "dotenv": "^8.2.0"
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # @source: https://github.com/xrkffgg/gitignore/blob/master/.gitignore
2 |
3 | # production
4 | /dist
5 | /docs-dist
6 |
7 | # Log file
8 | *.log
9 | npm-debug.log*
10 | yarn-debug.log*
11 | yarn-error.log*
12 |
13 | # Private
14 |
15 | # misc
16 | .DS_Store
17 |
18 | # dependencies
19 | node_modules
20 | yarn.lock
21 | package-lock.json
22 |
23 | # local env files
24 | .env.local
25 | .env.*.local
26 |
27 | # Compiled file
28 | *.class
29 | *.css.map
30 | *.sass.map
31 | *.scss.map
32 |
33 | # Editor directories and files
34 | .idea
35 | .vscode
36 | *.suo
37 | *.ntvs*
38 | *.njsproj
39 | *.sln
40 | *.sw?
41 | ~$*.*
42 |
43 | # umi
44 | .umi
45 | .umi-production
46 | .umi-test
47 | .env.local
48 |
49 | # cache
50 | .sass-cache/
51 |
52 | # test
53 | coverage
54 |
--------------------------------------------------------------------------------
/.github/workflows/auto-update.yml:
--------------------------------------------------------------------------------
1 | name: Update
2 |
3 | on:
4 | push:
5 | branches: main
6 | schedule:
7 | - cron: '0 0 * * *'
8 |
9 | jobs:
10 | update:
11 | runs-on: ubuntu-latest
12 | steps:
13 | - uses: actions/checkout@master
14 | - name: Install
15 | run: yarn
16 | - name: Update
17 | run: node main.js
18 | env:
19 | token: ${{ secrets.GITHUB_TOKEN }}
20 | - name: Commit and push if changed
21 | run: |-
22 | git diff
23 | git config user.email "github-actions[bot]@users.noreply.github.com"
24 | git config user.name "github-actions[bot]"
25 | git pull
26 | git add -A
27 | git commit -m "🤖 Auto update README" || exit 0
28 | git push
29 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021-present xrkffgg
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/main.js:
--------------------------------------------------------------------------------
1 | require('dotenv').config();
2 | const { Octokit } = require('@octokit/rest');
3 | const github = require('@actions/github');
4 | const { writeFileSync } = require('fs');
5 |
6 | async function run() {
7 | try {
8 | const { token } = process.env;
9 | const octokit = new Octokit({ auth: `token ${token}` });
10 | const username = github.context.repo.owner;
11 |
12 | async function queryFollowers(page = 1) {
13 | let { data: followers } = await octokit.users.listFollowersForUser({
14 | username,
15 | per_page: 100,
16 | page,
17 | });
18 | if (followers.length >= 100) {
19 | followers = followers.concat(await queryFollowers(page + 1));
20 | }
21 | return followers;
22 | }
23 |
24 | async function queryFollowing(page = 1) {
25 | let { data: following } = await octokit.users.listFollowingForUser({
26 | username,
27 | per_page: 100,
28 | page,
29 | });
30 | if (following.length >= 100) {
31 | following = following.concat(await queryFollowing(page + 1));
32 | }
33 | return following;
34 | }
35 |
36 | const { data: user } = await octokit.users.getByUsername({
37 | username,
38 | });
39 |
40 | const followers = await queryFollowers();
41 | followers.reverse();
42 | const following = await queryFollowing();
43 |
44 | const before = `# 😳 List All Followers And Following
45 |
46 | Easy view and filter all follows and following. Auto update by GitHub Action.
47 |
48 | - Since GitHub's default follows and following does not support paging and filtering
49 | - [How to use in my own project?](https://github.com/xrkffgg/list-all-followers-and-following/issues/1)
50 | - If you have any questions, please open a new [issue](https://github.com/xrkffgg/list-all-followers-and-following/issues)
51 |
52 | `;
53 |
54 | function dealBlog(blog) {
55 | if (blog) {
56 | return `[${blog}](https://${blog})`;
57 | }
58 | return '-';
59 | }
60 |
61 | const middle = `## ${username}
62 |
63 |
64 |
65 | | Name | Bio | Blog | Location | Company |
66 | | -- | -- | -- | -- | -- |
67 | | ${user.name || '-' } | ${user.bio || '-' } | ${dealBlog(user.blog)} | ${user.location || '-' } | ${getCompany(user.company)} |
68 |
69 | ## Followers ${followers.length}
70 |
71 |