diff options
author | Suzanne Selhorn <sselhorn@gitlab.com> | 2022-12-16 20:21:56 +0300 |
---|---|---|
committer | Suzanne Selhorn <sselhorn@gitlab.com> | 2022-12-16 20:21:56 +0300 |
commit | 45d6def9051e9ad7a6bb6a9abdf051e5328587c1 (patch) | |
tree | bd9bb0024d0da66c95c4048e6bcad872aafd9a16 | |
parent | e1560cc367011242883d553b877431b12f835776 (diff) | |
parent | 3bc18bde677932efd1647f4e0c8b439ff236f5c7 (diff) |
Merge branch 'sarahg/hackathon-script' into 'main'
Add a script for creating hackathon issues
See merge request https://gitlab.com/gitlab-org/gitlab-docs/-/merge_requests/3376
Merged-by: Suzanne Selhorn <sselhorn@gitlab.com>
Co-authored-by: Sarah German <sgerman@gitlab.com>
-rw-r--r-- | package.json | 1 | ||||
-rwxr-xr-x | scripts/create_issues.js | 99 | ||||
-rw-r--r-- | yarn.lock | 78 |
3 files changed, 178 insertions, 0 deletions
diff --git a/package.json b/package.json index 855427ad..4058c323 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "@vue/vue2-jest": "^28.0.1", "babel-jest": "^29.3.1", "eslint": "^8.29.0", + "fast-csv": "^4.3.6", "flush-promises": "^1.0.2", "jest": "^29.3.1", "jest-environment-jsdom": "^29.3.1", diff --git a/scripts/create_issues.js b/scripts/create_issues.js new file mode 100755 index 00000000..00227472 --- /dev/null +++ b/scripts/create_issues.js @@ -0,0 +1,99 @@ +#!/usr/bin/env node + +/** + * @file create_issues.js + * + * Issues created by this script are given hackathon-specific labels + * and populated with descriptions of Vale warnings from the given CSV. + * + * Prerequistes: + * 1. Install glab: https://gitlab.com/gitlab-org/cli + * 2. Log in: glab auth login + * 3. Run "yarn" in gitlab-docs to ensure node.js dependencies are up-to-date. + * + * Use the script: + * 1. Create a spreadsheet of Vale issues using this template. Do not remove or change the headers. + * https://docs.google.com/spreadsheets/d/1ukGT-1H-Qvik9GwCU1n0oAH9vofvkKvlL3ga8PaCXjw/edit?usp=sharing + * 2. Export the spreadsheet to a CSV, and remove spaces from the filename. + * 3. The script requires three variables to run: + * - CSV_PATH: Path to your CSV file + * - REPO: URL of the destination project + * - MILESTONE: Milestone for the issue + * 4. Prepend the above variables when calling the script, like this: + * CSV_PATH=Sheet1.csv REPO="https://gitlab.com/sselhorn/test-project" MILESTONE="15.9" ./scripts/create_issues.js + */ + +/* eslint-disable no-console */ +/* eslint-disable import/no-extraneous-dependencies */ + +const fs = require('fs'); +const { exec } = require('child_process'); +const csv = require('fast-csv'); + +const { CSV_PATH, REPO, MILESTONE } = process.env; +if (!CSV_PATH || !REPO || !MILESTONE) { + console.log('Missing a required parameter, exiting.'); + process.exit(); +} + +const LABELS = + 'Technical Writing,good for new contributors,Accepting merge requests,documentation,docs::improvement'; + +const TITLE_PREFIX = 'Fix Vale issues for'; +const ISSUE_INTRO = `The following issues occurred when we ran a linting tool called Vale against this Markdown page in the GitLab documentation. The first number on each line indicates the line number where the error occurred.\n\n +To fix the issues, open a merge request for the markdown file, which you can find in the [/doc](https://gitlab.com/gitlab-org/gitlab/-/blob/master/doc) directory. When you open the MR, a bot will automatically ping the appropriate GitLab technical writer. They will work with you to merge the changes.\n\n +If you feel any of these warnings are incorrect, please create an issue with the tw-test label so we can improve our Vale tests. Thank you!`; + +// Create GitLab issues from our CSV data. +const createIssues = (issues) => { + issues.forEach((issue) => { + const title = `${TITLE_PREFIX} ${issue.path}`; + + // Output the Vale warnings in a markdown table. + let warningsTable = '\n\n| Line | Rule | Suggestion |\n| --- | --- | --- |\n'; + issue.warnings.forEach((w) => { + warningsTable += `| ${w.line} | ${w.rule} | ${w.suggestion} |\n`; + }); + const description = ISSUE_INTRO + warningsTable; + + // Use GitLab CLI to create a confidential issue. + const command = `glab issue create -c -t "${title}" -d "${description}" -R ${REPO} -m ${MILESTONE} -l "${LABELS}"`; + exec(command, (error, stdout) => { + if (error) { + console.error('Unable to create issues, exiting. Check error.log for details.'); + // Write errors to a log file. + // Drop the command body since it's very long and obscures the actual error. + fs.appendFile( + 'error.log', + `[${new Date().toISOString()}]: ${error.toString().replace(command, '')}`, + (fsError) => { + if (fsError) throw fsError; + }, + ); + } else { + console.log(`Created new issue: ${stdout.replace('\n', '')}`); + } + }); + }); +}; + +// Read the CSV and group Vale warnings by path. +const issues = []; +fs.createReadStream(CSV_PATH) + .pipe(csv.parse({ headers: true })) + .on('error', (error) => console.error(error)) + .on('data', (row) => { + const warning = { + line: row.Line, + rule: row.Rule, + suggestion: row.Suggestion, + }; + const index = issues.findIndex((x) => x.path === row.Path); + + if (index >= 0) { + issues[index].warnings.push(warning); + } else { + issues.push({ path: row.Path, warnings: [warning] }); + } + }) + .on('end', () => createIssues(issues)); @@ -1148,6 +1148,31 @@ resolved "https://registry.yarnpkg.com/@evilmartians/lefthook/-/lefthook-1.2.4.tgz#e592d603db5fbf587fea8d560895d31c247818e7" integrity sha512-dZb/eleGFas3vs2qXtpcs85LzVUHt9f43D9MY6/DB1IFNIkFDhnTYzrZ25jTabqH1laiJ5hVHtpeH/xXOhMcnA== +"@fast-csv/format@4.3.5": + version "4.3.5" + resolved "https://registry.yarnpkg.com/@fast-csv/format/-/format-4.3.5.tgz#90d83d1b47b6aaf67be70d6118f84f3e12ee1ff3" + integrity sha512-8iRn6QF3I8Ak78lNAa+Gdl5MJJBM5vRHivFtMRUWINdevNo00K7OXxS2PshawLKTejVwieIlPmK5YlLu6w4u8A== + dependencies: + "@types/node" "^14.0.1" + lodash.escaperegexp "^4.1.2" + lodash.isboolean "^3.0.3" + lodash.isequal "^4.5.0" + lodash.isfunction "^3.0.9" + lodash.isnil "^4.0.0" + +"@fast-csv/parse@4.3.6": + version "4.3.6" + resolved "https://registry.yarnpkg.com/@fast-csv/parse/-/parse-4.3.6.tgz#ee47d0640ca0291034c7aa94039a744cfb019264" + integrity sha512-uRsLYksqpbDmWaSmzvJcuApSEe38+6NQZBUsuAyMZKqHxH0g1wcJgsKUvN3WC8tewaqFjBMMGrkHmC+T7k8LvA== + dependencies: + "@types/node" "^14.0.1" + lodash.escaperegexp "^4.1.2" + lodash.groupby "^4.6.0" + lodash.isfunction "^3.0.9" + lodash.isnil "^4.0.0" + lodash.isundefined "^3.0.1" + lodash.uniq "^4.5.0" + "@gitlab/eslint-plugin@^18.1.0": version "18.1.0" resolved "https://registry.yarnpkg.com/@gitlab/eslint-plugin/-/eslint-plugin-18.1.0.tgz#8300cc938f50114b3e74d97660721486c13caea5" @@ -1726,6 +1751,11 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-18.0.1.tgz#e91bd73239b338557a84d1f67f7b9e0f25643870" integrity sha512-CmR8+Tsy95hhwtZBKJBs0/FFq4XX7sDZHlGGf+0q+BRZfMbOTkzkj0AFAuTyXbObDIoanaBBW0+KEW+m3N16Wg== +"@types/node@^14.0.1": + version "14.18.34" + resolved "https://registry.yarnpkg.com/@types/node/-/node-14.18.34.tgz#cd2e6fa0dbfb08a62582a7b967558e73c32061ec" + integrity sha512-hcU9AIQVHmPnmjRK+XUUYlILlr9pQrsqSrwov/JK1pnf3GTQowVBhx54FbvM0AU/VXGH4i3+vgXS5EguR7fysA== + "@types/normalize-package-data@^2.4.0": version "2.4.1" resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz#d3357479a0fdfdd5907fe67e17e0a85c906e1301" @@ -3855,6 +3885,14 @@ fast-clone@^1.5.13: resolved "https://registry.yarnpkg.com/fast-clone/-/fast-clone-1.5.13.tgz#7fe17542ae1c872e71bf80d177d00c11f51c2ea7" integrity sha512-0ez7coyFBQFjZtId+RJqJ+EQs61w9xARfqjqK0AD9vIUkSxWD4HvPt80+5evebZ1tTnv1GYKrPTipx7kOW5ipA== +fast-csv@^4.3.6: + version "4.3.6" + resolved "https://registry.yarnpkg.com/fast-csv/-/fast-csv-4.3.6.tgz#70349bdd8fe4d66b1130d8c91820b64a21bc4a63" + integrity sha512-2RNSpuwwsJGP0frGsOmTb9oUF+VkFSM4SyLTDgwf2ciHWTarN0lQTC+F2f/t5J9QjW+c65VFIAAu85GsvMIusw== + dependencies: + "@fast-csv/format" "4.3.5" + "@fast-csv/parse" "4.3.6" + fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3: version "3.1.3" resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525" @@ -5335,6 +5373,41 @@ lodash.debounce@^4.0.8: resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af" integrity sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow== +lodash.escaperegexp@^4.1.2: + version "4.1.2" + resolved "https://registry.yarnpkg.com/lodash.escaperegexp/-/lodash.escaperegexp-4.1.2.tgz#64762c48618082518ac3df4ccf5d5886dae20347" + integrity sha512-TM9YBvyC84ZxE3rgfefxUWiQKLilstD6k7PTGt6wfbtXF8ixIJLOL3VYyV/z+ZiPLsVxAsKAFVwWlWeb2Y8Yyw== + +lodash.groupby@^4.6.0: + version "4.6.0" + resolved "https://registry.yarnpkg.com/lodash.groupby/-/lodash.groupby-4.6.0.tgz#0b08a1dcf68397c397855c3239783832df7403d1" + integrity sha512-5dcWxm23+VAoz+awKmBaiBvzox8+RqMgFhi7UvX9DHZr2HdxHXM/Wrf8cfKpsW37RNrvtPn6hSwNqurSILbmJw== + +lodash.isboolean@^3.0.3: + version "3.0.3" + resolved "https://registry.yarnpkg.com/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz#6c2e171db2a257cd96802fd43b01b20d5f5870f6" + integrity sha512-Bz5mupy2SVbPHURB98VAcw+aHh4vRV5IPNhILUCsOzRmsTmSQ17jIuqopAentWoehktxGd9e/hbIXq980/1QJg== + +lodash.isequal@^4.5.0: + version "4.5.0" + resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0" + integrity sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ== + +lodash.isfunction@^3.0.9: + version "3.0.9" + resolved "https://registry.yarnpkg.com/lodash.isfunction/-/lodash.isfunction-3.0.9.tgz#06de25df4db327ac931981d1bdb067e5af68d051" + integrity sha512-AirXNj15uRIMMPihnkInB4i3NHeb4iBtNg9WRWuK2o31S+ePwwNmDPaTL3o7dTJ+VXNZim7rFs4rxN4YU1oUJw== + +lodash.isnil@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/lodash.isnil/-/lodash.isnil-4.0.0.tgz#49e28cd559013458c814c5479d3c663a21bfaa6c" + integrity sha512-up2Mzq3545mwVnMhTDMdfoG1OurpA/s5t88JmQX809eH3C8491iu2sfKhTfhQtKY78oPNhiaHJUpT/dUDAAtng== + +lodash.isundefined@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/lodash.isundefined/-/lodash.isundefined-3.0.1.tgz#23ef3d9535565203a66cefd5b830f848911afb48" + integrity sha512-MXB1is3s899/cD8jheYYE2V9qTHwKvt+npCwpD+1Sxm3Q3cECXCiYHjeHWXNwr6Q0SOBPrYUDxendrO6goVTEA== + lodash.kebabcase@4.1.1: version "4.1.1" resolved "https://registry.yarnpkg.com/lodash.kebabcase/-/lodash.kebabcase-4.1.1.tgz#8489b1cb0d29ff88195cceca448ff6d6cc295c36" @@ -5355,6 +5428,11 @@ lodash.truncate@^4.4.2: resolved "https://registry.yarnpkg.com/lodash.truncate/-/lodash.truncate-4.4.2.tgz#5a350da0b1113b837ecfffd5812cbe58d6eae193" integrity sha512-jttmRe7bRse52OsWIMDLaXxWqRAmtIUccAQ3garviCqJjafXOfNMO0yMfNpdD6zbGaTU0P5Nz7e7gAT6cKmJRw== +lodash.uniq@^4.5.0: + version "4.5.0" + resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" + integrity sha512-xfBaXQd9ryd9dlSDvnvI0lvxfLJlYAZzXomUYzLKtUeOQvOP5piqAWuGtrhWeqaXK9hhoM/iyJc5AV+XfsX3HQ== + lodash.upperfirst@4.3.1: version "4.3.1" resolved "https://registry.yarnpkg.com/lodash.upperfirst/-/lodash.upperfirst-4.3.1.tgz#1365edf431480481ef0d1c68957a5ed99d49f7ce" |