Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32159363
generate-phab-tag-removal-script.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
generate-phab-tag-removal-script.js
View Options
/* eslint-disable flowtype/require-valid-file-annotation */
const
{
execSync
}
=
require
(
'child_process'
);
const
fs
=
require
(
'fs'
);
const
{
request
}
=
require
(
'gaxios'
);
const
PHABRICATOR_API_TOKEN
=
process
.
env
.
PHABRICATOR_API_TOKEN
;
if
(
!
PHABRICATOR_API_TOKEN
)
{
console
.
log
(
'ERROR: Unable to retrieve PHABRICATOR_API_TOKEN.'
);
process
.
exit
(
1
);
}
const
getDifferentialDataFromPhabricator
=
async
()
=>
{
return
await
request
({
url
:
'https://phab.comm.dev/api/differential.query'
,
params
:
{
'api.token'
:
PHABRICATOR_API_TOKEN
,
},
});
};
const
getRevisionsToBeRemoved
=
differentialData
=>
{
const
revisionsToBeRemoved
=
[];
for
(
const
diff
of
differentialData
.
data
[
'result'
])
{
if
(
diff
[
'statusName'
]
===
'Abandonded'
||
diff
[
'statusName'
]
===
'Closed'
)
{
revisionsToBeRemoved
.
push
(...
diff
[
'diffs'
]);
}
}
return
revisionsToBeRemoved
;
};
const
getRemoteGitTags
=
()
=>
{
const
remoteGitTags
=
execSync
(
'git tag'
);
return
new
Set
(
remoteGitTags
.
toString
().
split
(
'\n'
));
};
const
getGitTagsToBeRemoved
=
(
remoteGitTags
,
revisionsToBeRemoved
)
=>
{
const
gitTagsToBeRemoved
=
[];
for
(
const
revisionID
of
revisionsToBeRemoved
)
{
gitTagsToBeRemoved
.
push
(
`phabricator/base/
${
revisionID
}
`
);
gitTagsToBeRemoved
.
push
(
`phabricator/diff/
${
revisionID
}
`
);
}
return
gitTagsToBeRemoved
.
filter
(
tag
=>
remoteGitTags
.
has
(
tag
));
};
const
getGitCommandsToBeRun
=
gitTagsToBeRemoved
=>
{
return
gitTagsToBeRemoved
.
map
(
tag
=>
`git push --delete origin tag
${
tag
}
`
);
};
const
writeGitCommandsScriptToDisk
=
gitCommandsToBeRun
=>
{
fs
.
writeFileSync
(
'tag_removal_script.sh'
,
gitCommandsToBeRun
.
join
(
'\n'
));
};
async
function
main
()
{
const
differentialData
=
await
getDifferentialDataFromPhabricator
();
const
remoteGitTags
=
getRemoteGitTags
();
const
revisionsToBeRemoved
=
getRevisionsToBeRemoved
(
differentialData
);
const
gitTagsToBeRemoved
=
getGitTagsToBeRemoved
(
remoteGitTags
,
revisionsToBeRemoved
,
);
const
gitCommandsToBeRun
=
getGitCommandsToBeRun
(
gitTagsToBeRemoved
);
writeGitCommandsScriptToDisk
(
gitCommandsToBeRun
);
process
.
exit
(
0
);
}
main
();
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Sun, Dec 7, 4:30 PM (1 d, 10 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5578650
Default Alt Text
generate-phab-tag-removal-script.js (2 KB)
Attached To
Mode
rCOMM Comm
Attached
Detach File
Event Timeline
Log In to Comment