Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
challonge-migrator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
challonge-migrator
Commits
218c06c8
Commit
218c06c8
authored
Jan 30, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
finish
parent
9a98c5c1
Pipeline
#2281
passed with stages
in 49 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
3910 additions
and
18 deletions
+3910
-18
create.ts
create.ts
+2
-2
migrate.ts
migrate.ts
+24
-14
src/config.ts
src/config.ts
+2
-1
test.json
test.json
+3882
-1
No files found.
create.ts
View file @
218c06c8
...
...
@@ -9,7 +9,7 @@ let config: Config;
async
function
createTournament
(
oldTournamentData
:
any
)
{
const
oldData
=
_
.
clone
(
oldTournamentData
);
delete
oldData
.
url
;
oldData
.
name
+=
"
Imported
"
;
oldData
.
name
=
config
.
targetTournamentName
;
const
{
data
}
=
await
axios
.
post
(
"
https://api.challonge.com/v1/tournaments.json
"
,
{
api_key
:
config
.
apiKey
,
tournament
:
oldData
,
...
...
@@ -54,4 +54,4 @@ async function main() {
},
axiosPostConfig
);
console
.
log
(
`Finished.`
);
}
main
();
\ No newline at end of file
main
();
migrate.ts
View file @
218c06c8
...
...
@@ -56,12 +56,16 @@ async function checkQuit(round: number, oldPlayerId: number) {
}
const
nextRoundMatch
=
oldMatches
.
find
(
m
=>
m
.
round
===
round
+
1
&&
(
m
.
player1_id
===
oldPlayerId
||
m
.
player2_id
===
oldPlayerId
));
if
(
!
nextRoundMatch
)
{
console
.
log
(
`Player
${
oldPlayer
.
name
}
quitted in round
${
round
}
.`
);
const
newPlayerId
=
newParticipantNameMap
.
get
(
oldPlayer
.
name
).
id
;
await
axios
.
post
(
`https://api.challonge.com/v1/tournaments/
${
config
.
targetTournament
}
/participants/
${
newPlayerId
}
.json`
,
{
api_key
:
config
.
apiKey
,
_method
:
"
delete
"
},
axiosPostConfig
);
console
.
log
(
`Player
${
oldPlayer
.
name
}
:
${
oldPlayerId
}
/
${
newPlayerId
}
quitted in round
${
round
}
.`
);
try
{
await
axios
.
delete
(
`https://api.challonge.com/v1/tournaments/
${
config
.
targetTournament
}
/participants/
${
newPlayerId
}
.json?api_key=
${
encodeURIComponent
(
config
.
apiKey
)}
`
,
{
responseType
:
'
json
'
});
console
.
log
(
`Successfully quitting player
${
oldPlayer
.
name
}
in round
${
round
}
.`
);
}
catch
(
e
)
{
console
.
log
(
`Failed quitting player
${
oldPlayer
.
name
}
in round
${
round
}
:
${
e
.
toString
()}
`
);
}
}
}
...
...
@@ -91,14 +95,20 @@ async function migrateMatch(match: Match) {
}
const
oldPlayerIds
=
[
oldMatch
.
player1_id
,
oldMatch
.
player2_id
]
await
Promise
.
all
(
oldPlayerIds
.
map
(
pid
=>
checkQuit
(
match
.
round
,
pid
)));
await
axios
.
put
(
`https://api.challonge.com/v1/tournaments/
${
config
.
targetTournament
}
/matches/
${
match
.
id
}
.json`
,
{
api_key
:
config
.
apiKey
,
match
:
{
scores_csv
:
oldMatch
.
scores_csv
,
winner_id
}
},
axiosPostConfig
);
console
.
log
(
`Migrated match
${
currentMatchPlayer1Name
}
vs
${
currentMatchPlayer2Name
}
.`
);
try
{
await
axios
.
put
(
`https://api.challonge.com/v1/tournaments/
${
config
.
targetTournament
}
/matches/
${
match
.
id
}
.json`
,
{
api_key
:
config
.
apiKey
,
match
:
{
scores_csv
:
oldMatch
.
scores_csv
,
winner_id
}
},
axiosPostConfig
);
console
.
log
(
`Successfully migrated match
${
currentMatchPlayer1Name
}
vs
${
currentMatchPlayer2Name
}
.`
);
}
catch
(
e
)
{
console
.
error
(
`Failed migrating match
${
currentMatchPlayer1Name
}
vs
${
currentMatchPlayer2Name
}
:
${
e
.
toString
()}
`
);
}
}
...
...
@@ -118,4 +128,4 @@ async function main() {
}
console
.
log
(
`Finished.`
);
}
main
();
\ No newline at end of file
main
();
src/config.ts
View file @
218c06c8
...
...
@@ -6,6 +6,7 @@ export interface Config {
apiKey
:
string
;
sourceTournament
:
string
;
targetTournament
:
string
;
targetTournamentName
:
string
;
maxRounds
:
number
;
}
...
...
@@ -47,4 +48,4 @@ export async function loadConfig(): Promise<Config> {
export
async
function
writeConfig
(
config
:
Config
)
{
await
fs
.
promises
.
writeFile
(
"
./config.yaml
"
,
yaml
.
stringify
(
config
));
}
\ No newline at end of file
}
test.json
View file @
218c06c8
This source diff could not be displayed because it is too large. You can
view the blob
instead.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment