11#!/usr/bin/env node
22
3- const fs = require ( 'fs' )
4- const path = require ( 'path' )
5- const github = require ( '@actions/github' )
6- const enterpriseDates = require ( '../../lib/enterprise-dates' )
7- const { latest, oldestSupported } = require ( '../../lib/enterprise-server-releases' )
3+ import fs from 'fs'
4+ import path from 'path'
5+ import { getOctokit } from '@actions/github'
6+ import enterpriseDates from '../../lib/enterprise-dates.js'
7+ import { latest , oldestSupported } from '../../lib/enterprise-server-releases.js'
8+
89const acceptedMilestones = [ 'release' , 'deprecation' ]
910const teamsToCC = '/cc @github/docs-content @github/docs-engineering'
1011
@@ -19,47 +20,46 @@ const numberOfdaysBeforeDeprecationToOpenIssue = 15
1920// number of days.
2021//
2122// When a milestone is within the specified number of days, a new issue is
22- // created using the templates in
23- // .github/actions-scripts/enterprise-server-issue-templates.
23+ // created using the templates in
24+ // .github/actions-scripts/enterprise-server-issue-templates.
2425//
2526// Release issues are then added to the docs content squad board for triage.
26- // Deprecations issues are owned by docs engineering and are added to the
27+ // Deprecations issues are owned by docs engineering and are added to the
2728// docs engineering squad board automatically when the engineering label is added.
2829//
2930// [end-readme]
3031
3132run ( )
3233
33- async function run ( ) {
34-
35-
34+ async function run ( ) {
3635 const milestone = process . argv [ 2 ]
3736 if ( ! acceptedMilestones . includes ( milestone ) ) {
38- console . log ( ' Please specify either \ 'release\ ' or \ 'deprecation\ '\n' )
37+ console . log ( " Please specify either 'release' or 'deprecation'\n" )
3938 console . log ( 'Example: script/open-enterprise-issue.js release' )
4039 process . exit ( 1 )
4140 }
4241
43- const repoToOpenIssue = milestone === 'release' ? 'docs-content' : 'docs-engineering'
44-
4542 // Milestone-dependent values.
46- const numberOfdaysBeforeMilestoneToOpenIssue = milestone === 'release'
47- ? numberOfdaysBeforeReleaseToOpenIssue
48- : numberOfdaysBeforeDeprecationToOpenIssue
43+ const numberOfdaysBeforeMilestoneToOpenIssue =
44+ milestone === 'release'
45+ ? numberOfdaysBeforeReleaseToOpenIssue
46+ : numberOfdaysBeforeDeprecationToOpenIssue
4947
50- const versionNumber = milestone === 'release'
51- ? getNextVersionNumber ( )
52- : oldestSupported
48+ const versionNumber = milestone === 'release' ? getNextVersionNumber ( ) : oldestSupported
5349
5450 if ( ! versionNumber ) {
55- console . log ( `Could not find the next version number after ${ latest } in enterprise-dates.json. Try running script/udpate-enterprise-dates.js, then rerun this script.` )
51+ console . log (
52+ `Could not find the next version number after ${ latest } in enterprise-dates.json. Try running script/udpate-enterprise-dates.js, then rerun this script.`
53+ )
5654 process . exit ( 0 )
5755 }
5856
5957 const datesForVersion = enterpriseDates [ versionNumber ]
6058
6159 if ( ! datesForVersion ) {
62- console . log ( `Could not find ${ versionNumber } in enterprise-dates.json. Try running script/udpate-enterprise-dates.js, then rerun this script.` )
60+ console . log (
61+ `Could not find ${ versionNumber } in enterprise-dates.json. Try running script/udpate-enterprise-dates.js, then rerun this script.`
62+ )
6363 process . exit ( 0 )
6464 }
6565
@@ -68,12 +68,20 @@ async function run () {
6868
6969 // If the milestone is more than the specific days away, exit now.
7070 if ( daysUntilMilestone > numberOfdaysBeforeMilestoneToOpenIssue ) {
71- console . log ( `The ${ versionNumber } ${ milestone } is not until ${ nextMilestoneDate } ! An issue will be opened when it is ${ numberOfdaysBeforeMilestoneToOpenIssue } days away.` )
71+ console . log (
72+ `The ${ versionNumber } ${ milestone } is not until ${ nextMilestoneDate } ! An issue will be opened when it is ${ numberOfdaysBeforeMilestoneToOpenIssue } days away.`
73+ )
7274 process . exit ( 0 )
7375 }
7476
75- const milestoneSteps = fs . readFileSync ( path . join ( process . cwd ( ) , `.github/actions-scripts/enterprise-server-issue-templates/${ milestone } -issue.md` ) , 'utf8' )
76- const issueLabels = [ `enterprise ${ milestone } ` ]
77+ const milestoneSteps = fs . readFileSync (
78+ path . join (
79+ process . cwd ( ) ,
80+ `.github/actions-scripts/enterprise-server-issue-templates/${ milestone } -issue.md`
81+ ) ,
82+ 'utf8'
83+ )
84+ const issueLabels = [ `enterprise ${ milestone } ` , `engineering` ]
7785 const issueTitle = `[${ nextMilestoneDate } ] Enterprise Server ${ versionNumber } ${ milestone } (technical steps)`
7886
7987 const issueBody = `GHES ${ versionNumber } ${ milestone } occurs on ${ nextMilestoneDate } .
@@ -83,68 +91,70 @@ async function run () {
8391 const token = process . env . GITHUB_TOKEN
8492
8593 // Create the milestone issue
86- const octokit = github . getOctokit ( token )
94+ const octokit = getOctokit ( token )
8795 try {
8896 issue = await octokit . request ( 'POST /repos/{owner}/{repo}/issues' , {
8997 owner : 'github' ,
90- repo : repoToOpenIssue ,
98+ repo : 'docs-internal' ,
9199 title : issueTitle ,
92100 body : issueBody ,
93- labels : issueLabels
101+ labels : issueLabels ,
94102 } )
95103 if ( issue . status === 201 ) {
96104 // Write the values to disk for use in the workflow.
97- console . log ( `Issue #${ issue . data . number } for the ${ versionNumber } ${ milestone } was opened: ${ issue . data . html_url } ` )
105+ console . log (
106+ `Issue #${ issue . data . number } for the ${ versionNumber } ${ milestone } was opened: ${ issue . data . html_url } `
107+ )
98108 }
99109 } catch ( error ) {
100110 console . error ( `#ERROR# ${ error } ` )
101111 console . log ( `🛑 There was an error creating the issue.` )
102112 process . exit ( 1 )
103113 }
104114
105- // Add the release issue to the 'Needs triage' column on the
115+ // Add the release issue to the 'Needs triage' column on the
106116 // docs content squad project board:
107117 // https://github.com/orgs/github/projects/1773#column-12198119
108118 // Deprecation issues are owned by docs engineering only and will
109119 // be triaged by adding the engineering label to the issue.
110120 if ( milestone === 'release' ) {
111121 try {
112122 const addCard = await octokit . request ( 'POST /projects/columns/{column_id}/cards' , {
113- column_id : 12198119 ,
123+ column_id : 12198119 ,
114124 content_id : issue . data . id ,
115125 content_type : 'Issue' ,
116126 mediaType : {
117- previews : [
118- 'inertia'
119- ]
120- }
127+ previews : [ 'inertia' ] ,
128+ } ,
121129 } )
122130
123131 if ( addCard . status === 201 ) {
124132 // Write the values to disk for use in the workflow.
125- console . log ( `The issue #${ issue . data . number } was added to https://github.com/orgs/github/projects/1773#column-12198119.` )
126- }
127- } catch ( error ) {
133+ console . log (
134+ `The issue #${ issue . data . number } was added to https://github.com/orgs/github/projects/1773#column-12198119.`
135+ )
136+ }
137+ } catch ( error ) {
128138 console . error ( `#ERROR# ${ error } ` )
129139 console . log ( `🛑 There was an error adding the issue to the project board.` )
130140 process . exit ( 1 )
131141 }
132142 }
133143}
134144
135- function getNextVersionNumber ( ) {
145+ function getNextVersionNumber ( ) {
136146 const indexOfLatest = Object . keys ( enterpriseDates ) . indexOf ( latest )
137147 const indexOfNext = indexOfLatest + 1
138148 return Object . keys ( enterpriseDates ) [ indexOfNext ]
139149}
140150
141- function calculateDaysUntilMilestone ( nextMilestoneDate ) {
151+ function calculateDaysUntilMilestone ( nextMilestoneDate ) {
142152 const today = new Date ( ) . toISOString ( ) . slice ( 0 , 10 )
143153 const differenceInMilliseconds = getTime ( nextMilestoneDate ) - getTime ( today )
144154 // Return the difference in days
145- return Math . floor ( ( differenceInMilliseconds ) / ( 1000 * 60 * 60 * 24 ) )
155+ return Math . floor ( differenceInMilliseconds / ( 1000 * 60 * 60 * 24 ) )
146156}
147157
148- function getTime ( date ) {
158+ function getTime ( date ) {
149159 return new Date ( date ) . getTime ( )
150160}
0 commit comments