Skip to content

Commit 9541860

Browse files
Use a configuration object
Makes things much simpler to track & simplifies the code
1 parent 8326776 commit 9541860

File tree

8 files changed

+370
-316
lines changed

8 files changed

+370
-316
lines changed

flat-manager/dist/index.js

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4090,38 +4090,47 @@ var __webpack_exports__ = {};
40904090
const core = __nccwpck_require__(699)
40914091
const exec = __nccwpck_require__(922)
40924092

4093-
// FIXME: get this from the outputs of the flatpak-builder action
4094-
const LOCAL_REPO_NAME = 'repo'
4093+
class Configuration {
4094+
constructor () {
4095+
this.repository = core.getInput('repository')
4096+
this.flatManagerUrl = core.getInput('flat-manager-url')
4097+
this.token = core.getInput('token')
4098+
this.endOfLife = core.getInput('end-of-life')
4099+
this.endOfLifeRebase = core.getInput('end-of-life-rebase')
4100+
// FIXME: get this from the outputs of the flatpak-builder action
4101+
this.localRepoName = 'repo'
4102+
}
4103+
}
40954104

4096-
const run = (repository, flatManagerUrl, token, endOfLife, endOfLifeRebase) => {
4105+
const run = (config) => {
40974106
exec.exec('flatpak', [
40984107
'build-update-repo',
40994108
'--generate-static-deltas',
4100-
LOCAL_REPO_NAME
4109+
config.localRepoName
41014110
])
41024111
.then(async () => {
41034112
let buildId = ''
41044113
let args = [
41054114
'--token',
4106-
token
4115+
config.token
41074116
]
41084117

4109-
if (endOfLife) {
4110-
args.push_back(`--end-of-life=${endOfLife}`)
4118+
if (config.endOfLife) {
4119+
args.push_back(`--end-of-life=${config.endOfLife}`)
41114120
}
41124121

4113-
if (endOfLifeRebase) {
4114-
if (!endOfLife) {
4122+
if (config.endOfLifeRebase) {
4123+
if (!config.endOfLife) {
41154124
throw Error('end-of-life has to be set if you want to use end-of-life-rebase')
41164125
}
41174126

4118-
args.push_back(`--end-of-life-rebase=${endOfLifeRebase}`)
4127+
args.push_back(`--end-of-life-rebase=${config.endOfLifeRebase}`)
41194128
}
41204129

41214130
args = args.concat([
41224131
'create',
4123-
flatManagerUrl,
4124-
repository
4132+
config.flatManagerUrl,
4133+
config.repository
41254134
])
41264135

41274136
const exitCode = await exec.exec('flat-manager-client', args, {
@@ -4139,20 +4148,20 @@ const run = (repository, flatManagerUrl, token, endOfLife, endOfLifeRebase) => {
41394148
.then(async (buildId) => {
41404149
await exec.exec('flat-manager-client', [
41414150
'--token',
4142-
token,
4151+
config.token,
41434152
'push',
41444153
'--commit',
41454154
'--publish',
41464155
'--wait',
41474156
buildId,
4148-
LOCAL_REPO_NAME
4157+
config.localRepoName
41494158
])
41504159
return buildId
41514160
})
41524161
.then(async (buildId) => {
41534162
await exec.exec('flat-manager-client', [
41544163
'--token',
4155-
token,
4164+
config.token,
41564165
'purge',
41574166
buildId
41584167
])
@@ -4163,13 +4172,8 @@ const run = (repository, flatManagerUrl, token, endOfLife, endOfLifeRebase) => {
41634172
}
41644173

41654174
if (require.main === require.cache[eval('__filename')]) {
4166-
run(
4167-
core.getInput('repository'),
4168-
core.getInput('flat-manager-url'),
4169-
core.getInput('token'),
4170-
core.getInput('end-of-life'),
4171-
core.getInput('end-of-life-rebase')
4172-
)
4175+
const config = new Configuration()
4176+
run(config)
41734177
}
41744178

41754179
})();

flat-manager/index.js

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,47 @@
11
const core = require('@actions/core')
22
const exec = require('@actions/exec')
33

4-
// FIXME: get this from the outputs of the flatpak-builder action
5-
const LOCAL_REPO_NAME = 'repo'
4+
class Configuration {
5+
constructor () {
6+
this.repository = core.getInput('repository')
7+
this.flatManagerUrl = core.getInput('flat-manager-url')
8+
this.token = core.getInput('token')
9+
this.endOfLife = core.getInput('end-of-life')
10+
this.endOfLifeRebase = core.getInput('end-of-life-rebase')
11+
// FIXME: get this from the outputs of the flatpak-builder action
12+
this.localRepoName = 'repo'
13+
}
14+
}
615

7-
const run = (repository, flatManagerUrl, token, endOfLife, endOfLifeRebase) => {
16+
const run = (config) => {
817
exec.exec('flatpak', [
918
'build-update-repo',
1019
'--generate-static-deltas',
11-
LOCAL_REPO_NAME
20+
config.localRepoName
1221
])
1322
.then(async () => {
1423
let buildId = ''
1524
let args = [
1625
'--token',
17-
token
26+
config.token
1827
]
1928

20-
if (endOfLife) {
21-
args.push_back(`--end-of-life=${endOfLife}`)
29+
if (config.endOfLife) {
30+
args.push_back(`--end-of-life=${config.endOfLife}`)
2231
}
2332

24-
if (endOfLifeRebase) {
25-
if (!endOfLife) {
33+
if (config.endOfLifeRebase) {
34+
if (!config.endOfLife) {
2635
throw Error('end-of-life has to be set if you want to use end-of-life-rebase')
2736
}
2837

29-
args.push_back(`--end-of-life-rebase=${endOfLifeRebase}`)
38+
args.push_back(`--end-of-life-rebase=${config.endOfLifeRebase}`)
3039
}
3140

3241
args = args.concat([
3342
'create',
34-
flatManagerUrl,
35-
repository
43+
config.flatManagerUrl,
44+
config.repository
3645
])
3746

3847
const exitCode = await exec.exec('flat-manager-client', args, {
@@ -50,20 +59,20 @@ const run = (repository, flatManagerUrl, token, endOfLife, endOfLifeRebase) => {
5059
.then(async (buildId) => {
5160
await exec.exec('flat-manager-client', [
5261
'--token',
53-
token,
62+
config.token,
5463
'push',
5564
'--commit',
5665
'--publish',
5766
'--wait',
5867
buildId,
59-
LOCAL_REPO_NAME
68+
config.localRepoName
6069
])
6170
return buildId
6271
})
6372
.then(async (buildId) => {
6473
await exec.exec('flat-manager-client', [
6574
'--token',
66-
token,
75+
config.token,
6776
'purge',
6877
buildId
6978
])
@@ -74,11 +83,6 @@ const run = (repository, flatManagerUrl, token, endOfLife, endOfLifeRebase) => {
7483
}
7584

7685
if (require.main === module) {
77-
run(
78-
core.getInput('repository'),
79-
core.getInput('flat-manager-url'),
80-
core.getInput('token'),
81-
core.getInput('end-of-life'),
82-
core.getInput('end-of-life-rebase')
83-
)
86+
const config = new Configuration()
87+
run(config)
8488
}

flat-manager/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"eslint": "^8.37.0",
1111
"eslint-config-standard": "^17.0.0",
1212
"eslint-plugin-import": "^2.22.1",
13+
"eslint-plugin-n": "^15.7.0",
1314
"eslint-plugin-node": "^11.1.0",
1415
"eslint-plugin-promise": "^6.1.1",
1516
"jest": "^29.5.0"

flat-manager/yarn.lock

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,13 @@ buffer-from@^1.0.0:
973973
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.2.tgz#2b146a6fd72e80b4f55d255f35ed59a3a9a41bd5"
974974
integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==
975975

976+
builtins@^5.0.1:
977+
version "5.0.1"
978+
resolved "https://registry.yarnpkg.com/builtins/-/builtins-5.0.1.tgz#87f6db9ab0458be728564fa81d876d8d74552fa9"
979+
integrity sha512-qwVpFEHNfhYJIzNRBvd2C1kyo6jz3ZSMPyyuR47OPdiKWlbYnZNyDWuyR175qDnAJLiCo5fBBqPb3RiXgWlkOQ==
980+
dependencies:
981+
semver "^7.0.0"
982+
976983
call-bind@^1.0.0, call-bind@^1.0.2:
977984
version "1.0.2"
978985
resolved "https://registry.yarnpkg.com/call-bind/-/call-bind-1.0.2.tgz#b1d4e89e688119c3c9a903ad30abb2f6a919be3c"
@@ -1297,6 +1304,14 @@ eslint-plugin-es@^3.0.0:
12971304
eslint-utils "^2.0.0"
12981305
regexpp "^3.0.0"
12991306

1307+
eslint-plugin-es@^4.1.0:
1308+
version "4.1.0"
1309+
resolved "https://registry.yarnpkg.com/eslint-plugin-es/-/eslint-plugin-es-4.1.0.tgz#f0822f0c18a535a97c3e714e89f88586a7641ec9"
1310+
integrity sha512-GILhQTnjYE2WorX5Jyi5i4dz5ALWxBIdQECVQavL6s7cI76IZTDWleTHkxz/QT3kvcs2QlGHvKLYsSlPOlPXnQ==
1311+
dependencies:
1312+
eslint-utils "^2.0.0"
1313+
regexpp "^3.0.0"
1314+
13001315
eslint-plugin-import@^2.22.1:
13011316
version "2.27.5"
13021317
resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.27.5.tgz#876a6d03f52608a3e5bb439c2550588e51dd6c65"
@@ -1318,6 +1333,20 @@ eslint-plugin-import@^2.22.1:
13181333
semver "^6.3.0"
13191334
tsconfig-paths "^3.14.1"
13201335

1336+
eslint-plugin-n@^15.7.0:
1337+
version "15.7.0"
1338+
resolved "https://registry.yarnpkg.com/eslint-plugin-n/-/eslint-plugin-n-15.7.0.tgz#e29221d8f5174f84d18f2eb94765f2eeea033b90"
1339+
integrity sha512-jDex9s7D/Qial8AGVIHq4W7NswpUD5DPDL2RH8Lzd9EloWUuvUkHfv4FRLMipH5q2UtyurorBkPeNi1wVWNh3Q==
1340+
dependencies:
1341+
builtins "^5.0.1"
1342+
eslint-plugin-es "^4.1.0"
1343+
eslint-utils "^3.0.0"
1344+
ignore "^5.1.1"
1345+
is-core-module "^2.11.0"
1346+
minimatch "^3.1.2"
1347+
resolve "^1.22.1"
1348+
semver "^7.3.8"
1349+
13211350
eslint-plugin-node@^11.1.0:
13221351
version "11.1.0"
13231352
resolved "https://registry.yarnpkg.com/eslint-plugin-node/-/eslint-plugin-node-11.1.0.tgz#c95544416ee4ada26740a30474eefc5402dc671d"
@@ -1350,11 +1379,23 @@ eslint-utils@^2.0.0:
13501379
dependencies:
13511380
eslint-visitor-keys "^1.1.0"
13521381

1382+
eslint-utils@^3.0.0:
1383+
version "3.0.0"
1384+
resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-3.0.0.tgz#8aebaface7345bb33559db0a1f13a1d2d48c3672"
1385+
integrity sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA==
1386+
dependencies:
1387+
eslint-visitor-keys "^2.0.0"
1388+
13531389
eslint-visitor-keys@^1.1.0:
13541390
version "1.3.0"
13551391
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz#30ebd1ef7c2fdff01c3a4f151044af25fab0523e"
13561392
integrity sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==
13571393

1394+
eslint-visitor-keys@^2.0.0:
1395+
version "2.1.0"
1396+
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz#f65328259305927392c938ed44eb0a5c9b2bd303"
1397+
integrity sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==
1398+
13581399
eslint-visitor-keys@^3.3.0, eslint-visitor-keys@^3.4.0:
13591400
version "3.4.0"
13601401
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.4.0.tgz#c7f0f956124ce677047ddbc192a68f999454dedc"
@@ -2798,7 +2839,7 @@ semver@^6.0.0, semver@^6.1.0, semver@^6.3.0:
27982839
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
27992840
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==
28002841

2801-
semver@^7.3.5:
2842+
semver@^7.0.0, semver@^7.3.5, semver@^7.3.8:
28022843
version "7.3.8"
28032844
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.8.tgz#07a78feafb3f7b32347d725e33de7e2a2df67798"
28042845
integrity sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==

0 commit comments

Comments
 (0)