[READ-ONLY] Mirror of https://github.com/probablykasper/readme-template-action. Integrate GitHub API data in your README.md
0

Configure Feed

Select the types of activity you want to include in your feed.

Add custom query support

Kasper (Aug 23, 2020, 6:38 PM +0200) 5204ed2b fcca4e89

+243 -103
+14 -12
EXAMPLE_OUTPUT.md
··· 1 1 # Example 2 2 3 3 4 + ## latest vidl release (custom) 5 + 6 + [vidl 3.5.0](https://github.com/probablykasper/vidl/releases/tag/3.5.0) (21 days ago) 7 + 4 8 ## Specific repos (custom) 5 9 6 10 | ⭐️Stars | 🗓Created | 📦Repo | 📚Description | 7 11 | --------- | -------- | ----------- | -------------- | 8 - | 1 | 2017-10-04T17:20:51Z | [probablykasper/vidl](https://github.com/probablykasper/vidl) | Python script for downloading video/audio | 9 - | 75686 | 2014-08-19T04:33:40Z | [golang/go](https://github.com/golang/go) | The Go programming language | 10 - | 0 | 2020-08-16T02:48:43Z | [probablykasper/embler](https://github.com/probablykasper/embler) | Turn binaries into applications | 12 + | 1 | 2017 October 4th | [probablykasper/vidl](https://github.com/probablykasper/vidl) | Python script for downloading video/audio | 13 + | 75706 | 2014 August 19th | [golang/go](https://github.com/golang/go) | The Go programming language | 14 + | 0 | 2020 August 16th | [probablykasper/embler](https://github.com/probablykasper/embler) | Turn binaries into applications | 11 15 12 16 ## 2 most starred repos list (custom) 13 17 ··· 28 32 - **TWITTER_USERNAME**: probablykasper 29 33 - **AVATAR_URL**: https://avatars0.githubusercontent.com/u/11315492?u=c501da00e9b817ffc78faab6c630f236ac2738cf&v=4 30 34 - **WEBSITE_URL**: https://kasper.space/ 31 - - **SIGNUP_DATE**: 2015-03-04T14:48:35Z 32 - - **SIGNUP_YYYY**: 2015 33 - - **SIGNUP_M**: 3 34 - - **SIGNUP_MMM**: Mar 35 - - **SIGNUP_MMMM**: March 36 - - **SIGNUP_D**: 4 37 - - **SIGNUP_DO**: 4th 38 - - **TOTAL_REPOS_SIZE_KB**: 707434 39 - - **TOTAL_REPOS_SIZE_MB**: 707.4 35 + - **SIGNUP_TIMESTAMP**: 2015-03-04T14:48:35Z 36 + - **SIGNUP_DATE**: March 4th 2015 37 + - **SIGNUP_DATE2**: 2015-03-04 38 + - **SIGNUP_YEAR**: 2015 39 + - **SIGNUP_AGO**: 5 years ago 40 + - **TOTAL_REPOS_SIZE_KB**: 707453 41 + - **TOTAL_REPOS_SIZE_MB**: 707.5 40 42 - **TOTAL_REPOS_SIZE_GB**: 0.71 41 43 - **TOTAL_REPOSITORIES**: 46 42 44
+61 -28
EXAMPLE_TEMPLATE.md
··· 3 3 ```js 4 4 // {{ TEMPLATE: }} 5 5 module.exports = { 6 - "2_MOST_STARRED_REPOS": { 7 - type: 'repos', 8 - params: ` 9 - first: 2, 10 - privacy: PUBLIC, 11 - ownerAffiliations:[OWNER], 12 - orderBy: { field:STARGAZERS, direction: DESC }, 13 - `, 6 + CUSTOM_PINNED_REPOS: { 7 + type: 'specificRepos', 8 + repos: [ 9 + 'vidl', 10 + 'golang/go', 11 + 'probablykasper/embler', 12 + ], 13 + }, 14 + "2_MOST_STARRED_REPOS": { 15 + type: 'repos', 16 + params: ` 17 + first: 2, 18 + privacy: PUBLIC, 19 + ownerAffiliations:[OWNER], 20 + orderBy: { field:STARGAZERS, direction: DESC }, 21 + `, 22 + modifyVariables: function(repo, moment, user) { 23 + repo.REPO_CREATED_MYDATE = moment(repo.REPO_CREATED_TIMESTAMP).format('YYYY MMMM Do') 24 + return repo 14 25 }, 15 - CUSTOM_PINNED_REPOS: { 16 - type: 'specificRepos', 17 - repos: [ 18 - 'vidl', 19 - 'golang/go', 20 - 'probablykasper/embler', 21 - ], 22 - modifyVariables: function(repo) { 23 - repo.REPO_CREATED_YYYY = new Date(repo.REPO_CREATED_DATE).getFullYear() 24 - return repo 25 - }, 26 - }, 26 + }, 27 + LATEST_VIDL_RELEASE: { 28 + type: 'customQuery', 29 + loop: false, 30 + query: async (octokit, moment, user) => { 31 + // You can do anything you want with the GitHub API here. 32 + const result = await octokit.graphql(` 33 + query { 34 + repository(name: "vidl", owner: "${user.USERNAME}") { 35 + releases(last: 1) { 36 + edges { 37 + node { 38 + url 39 + publishedAt 40 + tagName 41 + } 42 + } 43 + } 44 + } 45 + } 46 + `) 47 + const release = result.repository.releases.edges[0].node 48 + const date = new Date(release.publishedAt) 49 + // We have `loop: false`, so we return an object. 50 + // If we had `loop: true`, we would return an array of objects. 51 + return { 52 + VIDL_RELEASE_TAG: release.tagName, 53 + VIDL_RELEASE_URL: release.url, 54 + VIDL_RELEASE_WHEN: moment(release.publishedAt).fromNow(), 55 + } 56 + } 57 + } 27 58 } 28 59 // {{ :TEMPLATE }} 29 60 ``` 30 61 62 + ## latest vidl release (custom) 63 + 64 + [vidl {{ VIDL_RELEASE_TAG }}]({{ VIDL_RELEASE_URL }}) ({{ VIDL_RELEASE_WHEN }}) 65 + 31 66 ## Specific repos (custom) 32 67 33 68 | ⭐️Stars | 🗓Created | 📦Repo | 📚Description | 34 69 | --------- | -------- | ----------- | -------------- | 35 70 {{ loop CUSTOM_PINNED_REPOS }} 36 - | {{ REPO_STARS }} | {{ REPO_CREATED_DATE }} | [{{ REPO_FULL_NAME }}]({{ REPO_URL }}) | {{ REPO_DESCRIPTION }} | 71 + | {{ REPO_STARS }} | {{ REPO_CREATED_MYDATE }} | [{{ REPO_FULL_NAME }}]({{ REPO_URL }}) | {{ REPO_DESCRIPTION }} | 37 72 {{ end CUSTOM_PINNED_REPOS }} 38 73 39 74 ## 2 most starred repos list (custom) ··· 55 90 - **TWITTER_USERNAME**: {{ TWITTER_USERNAME }} 56 91 - **AVATAR_URL**: {{ AVATAR_URL }} 57 92 - **WEBSITE_URL**: {{ WEBSITE_URL }} 58 - - **SIGNUP_DATE**: {{ SIGNUP_DATE }} 59 - - **SIGNUP_YYYY**: {{ SIGNUP_YYYY }} 60 - - **SIGNUP_M**: {{ SIGNUP_M }} 61 - - **SIGNUP_MMM**: {{ SIGNUP_MMM }} 62 - - **SIGNUP_MMMM**: {{ SIGNUP_MMMM }} 63 - - **SIGNUP_D**: {{ SIGNUP_D }} 64 - - **SIGNUP_DO**: {{ SIGNUP_DO }} 93 + - **SIGNUP_TIMESTAMP**: {{ SIGNUP_TIMESTAMP }} 94 + - **SIGNUP_DATE**: {{ SIGNUP_DATE }} 95 + - **SIGNUP_DATE2**: {{ SIGNUP_DATE2 }} 96 + - **SIGNUP_YEAR**: {{ SIGNUP_YEAR }} 97 + - **SIGNUP_AGO**: {{ SIGNUP_AGO }} 65 98 - **TOTAL_REPOS_SIZE_KB**: {{ TOTAL_REPOS_SIZE_KB }} 66 99 - **TOTAL_REPOS_SIZE_MB**: {{ TOTAL_REPOS_SIZE_MB }} 67 100 - **TOTAL_REPOS_SIZE_GB**: {{ TOTAL_REPOS_SIZE_GB }}
+130 -42
README.md
··· 76 76 77 77 ### Normal variables you can put into your template file 78 78 79 - | Variable | Example | 80 - | ------------------------- | ------- | 81 - | {{ USERNAME }} | probablykasper | 82 - | {{ NAME }} | Kasper | 83 - | {{ EMAIL }} | email@example.com | 84 - | {{ USER_ID }} | MDQ6VXNlcjExMzE1NDky | 85 - | {{ BIO }} | Fullstack developer from Norway | 86 - | {{ COMPANY }} | Microscopicsoft | 87 - | {{ SIGNUP_DATE }} | 2015-03-04T14:48:35Z | 88 - | {{ LOCATION }} | Norway | 89 - | {{ TWITTER_USERNAME }} | probablykasper | 90 - | {{ AVATAR_URL }} | https://avatars0.githubusercontent.com/u/11315492u=c501da00e9b817ffc78faab6c630f236ac2738cf&v=4 | 91 - | {{ WEBSITE_URL }} | https://kasper.space/ | 92 - | {{ SIGNUP_YYYY }} | 2015 | 93 - | {{ SIGNUP_M }} | 3 | 94 - | {{ SIGNUP_MMM }} | Mar | 95 - | {{ SIGNUP_MMMM }} | March | 96 - | {{ SIGNUP_D }} | 4 | 97 - | {{ SIGNUP_DO }} | 4th | 98 - | {{ TOTAL_REPOS_SIZE_KB }} | 707403 | 99 - | {{ TOTAL_REPOS_SIZE_MB }} | 707.4 | 100 - | {{ TOTAL_REPOS_SIZE_GB }} | 0.71 | 101 - | {{ TOTAL_REPOSITORIES }} | 70740 | 79 + | Variable | Example | 80 + | ------------------------ | ------- | 81 + | {{ USERNAME}} | probablykasper 82 + | {{ NAME}} | Kasper 83 + | {{ EMAIL}} | email@example.com 84 + | {{ USER_ID}} | MDQ6VXNlcjExMzE1NDky 85 + | {{ BIO}} | Fullstack developer from Norway 86 + | {{ COMPANY}} | Microscopicsoft 87 + | {{ LOCATION}} | Norway 88 + | {{ TWITTER_USERNAME}} | probablykasper 89 + | {{ AVATAR_URL}} | https://avatars0.githubusercontent.com/u/11315492?u=c501da00e9b817ffc78faab6c630f236ac2738cf&v=4 90 + | {{ WEBSITE_URL}} | https://kasper.space/ 91 + | {{ SIGNUP_TIMESTAMP}} | 2015-03-04T14:48:35Z 92 + | {{ SIGNUP_DATE}} | March 4th 2015 93 + | {{ SIGNUP_DATE2}} | 2015-03-04 94 + | {{ SIGNUP_YEAR}} | 2015 95 + | {{ SIGNUP_AGO}} | 5 years ago 96 + | {{ TOTAL_REPOS_SIZE_KB}} | 707453 97 + | {{ TOTAL_REPOS_SIZE_MB}} | 707.5 98 + | {{ TOTAL_REPOS_SIZE_GB}} | 0.71 99 + | {{ TOTAL_REPOSITORIES}} | 46 102 100 103 101 ### Variables you can put inside `repo` loops 104 102 105 - | Variable | Example | 106 - | ------------------------- | ------- | 107 - | {{ REPO_NAME }} | cpc 108 - | {{ REPO_FULL_NAME }} | probablykasper/cpc 109 - | {{ REPO_OWNER_USERNAME }} | probablykasper 110 - | {{ REPO_DESCRIPTION }} | Text calculator with support for units and conversion | 111 - | {{ REPO_URL }} | https://github.com/probablykasper/cpc 112 - | {{ REPO_HOMEPAGE_URL }} | https://rust-lang.org/ 113 - | {{ REPO_CREATED_DATE }} | 2019-12-05T22:45:04Z 114 - | {{ REPO_PUSHED_DATE }} | 2020-08-20T20:13:22Z 115 - | {{ REPO_UPDATED_DATE }} | 2020-08-20T20:13:25Z 116 - | {{ REPO_FORK_COUNT }} | 0 117 - | {{ REPO_ID }} | MDEwOlJlcG9zaXRvcnkyMjYyMDE5NTU= 118 - | {{ REPO_STARS }} | 0 119 - | {{ REPO_LANGUAGE }} | Rust 120 - | {{ REPO_SIZE_KB }} | 1268285 121 - | {{ REPO_SIZE_MB }} | 1268.3 122 - | {{ REPO_SIZE_GB }} | 1.27 103 + | Variable | Example | 104 + | ---------------------------- | ------- | 105 + | {{ REPO_NAME }} | cpc 106 + | {{ REPO_FULL_NAME }} | probablykasper/cpc 107 + | {{ REPO_DESCRIPTION }} | Text calculator with support for units and conversion 108 + | {{ REPO_URL }} | https://github.com/probablykasper/cpc 109 + | {{ REPO_HOMEPAGE_URL }} | https://rust-lang.org/ 110 + | {{ REPO_CREATED_TIMESTAMP }} | 2019-12-05T22:45:04Z 111 + | {{ REPO_PUSHED_TIMESTAMP }} | 2020-08-20T20:13:22Z 112 + | {{ REPO_FORK_COUNT }} | 2 113 + | {{ REPO_ID }} | MDEwOlJlcG9zaXRvcnkyMjYyMDE5NTU= 114 + | {{ REPO_CREATED_DATE }} | December 5th 2019 115 + | {{ REPO_CREATED_DATE2 }} | 2019-12-05 116 + | {{ REPO_CREATED_YEAR }} | 2019 117 + | {{ REPO_CREATED_AGO }} | 9 months ago 118 + | {{ REPO_PUSHED_DATE }} | August 20th 2020 119 + | {{ REPO_PUSHED_DATE2 }} | 2020-08-20 120 + | {{ REPO_PUSHED_YEAR }} | 2020 121 + | {{ REPO_PUSHED_AGO }} | 3 days ago 122 + | {{ REPO_STARS }} | 5 123 + | {{ REPO_LANGUAGE }} | Rust 124 + | {{ REPO_OWNER_USERNAME }} | probablykasper 125 + | {{ REPO_SIZE_KB }} | 1268285 126 + | {{ REPO_SIZE_MB }} | 1268.3 127 + | {{ REPO_SIZE_GB }} | 1.27 123 128 124 129 ## Loops 125 130 ··· 167 172 168 173 ## Advanced usage 169 174 170 - If you want to show less starred repos, 175 + Check out [`EXAMPLE_TEMPLATE.md`](./EXAMPLE_TEMPLATE.md) and [`EXAMPLE_OUTPUT.md`](./EXAMPLE_TEMPLATE.md) to see examples and their outputs. 176 + 177 + For advanced usage, add a code block like this to your template: 178 + 179 + ````markdown 180 + ```js 181 + // {{ TEMPLATE: }} 182 + module.exports = { 183 + // ... custom vairables/loops 184 + } 185 + // {{ :TEMPLATE }} 186 + ```` 187 + 188 + To get a list of specific repos: 189 + 190 + ```js 191 + CUSTOM_PINNED_REPOS: { 192 + type: 'specificRepos', 193 + repos: [ 'vidl', 'golang/go', 'probablykasper/embler' ], 194 + }, 195 + ``` 196 + 197 + To get repos using custom parameters: 198 + 199 + ```js 200 + "2_MOST_STARRED_REPOS": { 201 + type: 'repos', 202 + params: ` 203 + first: 2, 204 + privacy: PUBLIC, 205 + ownerAffiliations:[OWNER], 206 + orderBy: { field:STARGAZERS, direction: DESC }, 207 + `, 208 + }, 209 + ``` 210 + 211 + Add a `modifyVariables` function to overwrite/add variables: 212 + 213 + ```js 214 + CUSTOM_PINNED_REPOS: { 215 + type: 'specificRepos', 216 + repos: [ 'vidl' ], 217 + modifyVariables: function(repo, moment, user) { 218 + repo.REPO_CREATED_MYDATE = moment(repo.REPO_CREATED_TIMESTAMP).format('YYYY MMMM Do') 219 + return repo 220 + }, 221 + }, 222 + ``` 223 + 224 + Add a custom query: 225 + 226 + ```js 227 + LATEST_VIDL_RELEASE: { 228 + type: 'customQuery', 229 + loop: false, 230 + query: async (octokit, moment, user) => { 231 + // You can do anything you want with the GitHub API here. 232 + const result = await octokit.graphql(` 233 + query { 234 + repository(name: "vidl", owner: "${user.USERNAME}") { 235 + releases(last: 1) { 236 + edges { 237 + node { 238 + url 239 + publishedAt 240 + tagName 241 + } 242 + } 243 + } 244 + } 245 + } 246 + `) 247 + const release = result.repository.releases.edges[0].node 248 + const date = new Date(release.publishedAt) 249 + // We have `loop: false`, so we return an object. 250 + // If we had `loop: true`, we would return an array of objects. 251 + return { 252 + VIDL_RELEASE_TAG: release.tagName, 253 + VIDL_RELEASE_URL: release.url, 254 + VIDL_RELEASE_WHEN: moment(release.publishedAt).fromNow(), 255 + } 256 + } 257 + } 258 + ``` 171 259 172 260 ## Dev instructions 173 261
+20 -1
index.js
··· 1 1 const core = require('@actions/core') 2 2 const fs = require('fs') 3 + const moment = require('moment') 3 4 const queries = require('./src/queries.js') 4 5 const { 5 6 newErr, ··· 130 131 : await queries.getSpecificRepos(user.USERNAME, template.repos) 131 132 if (typeof template.modifyVariables === 'function') { 132 133 for (let i = 0; i < repos.length; i++) { 133 - repos[i] = template.modifyVariables(repos[i]) 134 + repos[i] = template.modifyVariables(repos[i], moment, user) 134 135 } 135 136 } 136 137 console.log(' - Injecting') 137 138 return repos 138 139 }) 139 140 141 + } else if (template.type === 'customQuery') { 142 + 143 + console.log(templateName, '(customQuery)') 144 + if (template.loop) { 145 + console.log(' - Looking for') 146 + outputStr = await injectLoop(outputStr, templateName, async () => { 147 + console.log(' - Fetching') 148 + const resultArray = await template.query(queries.octokit, moment, user) 149 + console.log(' - Injecting') 150 + return resultArray 151 + }) 152 + } else { 153 + console.log(' - Fetching') 154 + const resultObject = await template.query(queries.octokit, moment, user) 155 + console.log(' - Injecting') 156 + outputStr = inject(outputStr, resultObject) 157 + } 158 + 140 159 } else { 141 160 throw new Error(`Invalid template type "${template.type}"`) 142 161 }
+18 -20
src/queries.js
··· 4 4 5 5 const ghToken = core.getInput('GITHUB_TOKEN') 6 6 const octokit = github.getOctokit(ghToken) 7 + module.exports.octokit = octokit 7 8 8 9 module.exports.getUser = async function() { 9 10 const queryResult = await octokit.graphql(` ··· 15 16 USER_ID: id 16 17 BIO: bio 17 18 COMPANY: company 18 - createdAt 19 + SIGNUP_TIMESTAMP: createdAt 19 20 LOCATION: location 20 21 TWITTER_USERNAME: twitterUsername 21 22 AVATAR_URL: avatarUrl ··· 31 32 const user = queryResult.viewer 32 33 33 34 const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] 34 - user.SIGNUP_DATE = moment(user.createdAt).format('MMMM Do YYYY') 35 - user.SIGNUP_DATE2 = moment(user.createdAt).format('YYYY-MM-DD') 36 - user.SIGNUP_YEAR = moment(user.createdAt).format('YYYY') 37 - user.SIGNUP_AGO = moment(user.createdAt).format('YYYY').fromNow() 38 - delete user.createdAt 35 + user.SIGNUP_DATE = moment(user.SIGNUP_TIMESTAMP).format('MMMM Do YYYY') 36 + user.SIGNUP_DATE2 = moment(user.SIGNUP_TIMESTAMP).format('YYYY-MM-DD') 37 + user.SIGNUP_YEAR = moment(user.SIGNUP_TIMESTAMP).format('YYYY') 38 + user.SIGNUP_AGO = moment(user.SIGNUP_TIMESTAMP).fromNow() 39 39 user.TOTAL_REPOS_SIZE_KB = user.repositories.totalDiskUsage 40 40 user.TOTAL_REPOS_SIZE_MB = Math.round(user.repositories.totalDiskUsage/1000*10)/10 41 41 user.TOTAL_REPOS_SIZE_GB = Math.round(user.repositories.totalDiskUsage/1000/1000*100)/100 ··· 47 47 48 48 function fixRepoValues(repo) { 49 49 50 - repo.REPO_CREATED_DATE = moment(repo.createdAt).format('MMMM Do YYYY') 51 - repo.REPO_CREATED_DATE2 = moment(repo.createdAt).format('YYYY-MM-DD') 52 - repo.REPO_CREATED_YEAR = moment(repo.createdAt).format('YYYY') 53 - repo.REPO_CREATED_AGO = moment(repo.createdAt).format('YYYY').fromNow() 54 - delete repo.createdAt 50 + repo.REPO_CREATED_DATE = moment(repo.REPO_CREATED_TIMESTAMP).format('MMMM Do YYYY') 51 + repo.REPO_CREATED_DATE2 = moment(repo.REPO_CREATED_TIMESTAMP).format('YYYY-MM-DD') 52 + repo.REPO_CREATED_YEAR = moment(repo.REPO_CREATED_TIMESTAMP).format('YYYY') 53 + repo.REPO_CREATED_AGO = moment(repo.REPO_CREATED_TIMESTAMP).fromNow() 55 54 56 - repo.REPO_PUSHED_DATE = moment(repo.pushedAt).format('MMMM Do YYYY') 57 - repo.REPO_PUSHED_DATE2 = moment(repo.pushedAt).format('YYYY-MM-DD') 58 - repo.REPO_PUSHED_YEAR = moment(repo.pushedAt).format('YYYY') 59 - repo.REPO_PUSHED_AGO = moment(repo.pushedAt).format('YYYY').fromNow() 60 - delete repo.pushedAt 55 + repo.REPO_PUSHED_DATE = moment(repo.REPO_PUSHED_TIMESTAMP).format('MMMM Do YYYY') 56 + repo.REPO_PUSHED_DATE2 = moment(repo.REPO_PUSHED_TIMESTAMP).format('YYYY-MM-DD') 57 + repo.REPO_PUSHED_YEAR = moment(repo.REPO_PUSHED_TIMESTAMP).format('YYYY') 58 + repo.REPO_PUSHED_AGO = moment(repo.REPO_PUSHED_TIMESTAMP).fromNow() 61 59 62 60 repo.REPO_STARS = repo.stargazers.totalCount 63 61 delete repo.stargazers ··· 96 94 REPO_DESCRIPTION: description 97 95 REPO_URL: url 98 96 REPO_HOMEPAGE_URL: homepageUrl 99 - REPO_CREATED_DATE: createdAt 100 - REPO_PUSHED_DATE: pushedAt 97 + REPO_CREATED_TIMESTAMP: createdAt 98 + REPO_PUSHED_TIMESTAMP: pushedAt 101 99 diskUsage 102 100 REPO_FORK_COUNT: forkCount 103 101 REPO_ID: id ··· 149 147 REPO_DESCRIPTION: description 150 148 REPO_URL: url 151 149 REPO_HOMEPAGE_URL: homepageUrl 152 - REPO_CREATED_DATE: createdAt 153 - REPO_PUSHED_DATE: pushedAt 150 + REPO_CREATED_TIMESTAMP: createdAt 151 + REPO_PUSHED_TIMESTAMP: pushedAt 154 152 REPO_FORK_COUNT: forkCount 155 153 REPO_ID: id 156 154 diskUsage