Skip to content

Commit 3006edc

Browse files
authored
Merge branch 'ServiceNowDevProgram:main' into main
2 parents b3b00eb + f85706e commit 3006edc

File tree

2,219 files changed

+40496
-3760
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,219 files changed

+40496
-3760
lines changed

.github/pull_request_template.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Pull Request Checklist
2+
3+
## Overview
4+
- [ ] I have read and understood the [CONTRIBUTING.md](CONTRIBUTING.md) guidelines
5+
- [ ] My pull request has a descriptive title that accurately reflects the changes
6+
- [ ] I've included only files relevant to the changes described in the PR title and description
7+
- [ ] I've created a new branch in my forked repository for this contribution
8+
9+
## Code Quality
10+
- [ ] My code is relevant to ServiceNow developers
11+
- [ ] My code snippets expand meaningfully on official ServiceNow documentation (if applicable)
12+
- [ ] I've disclosed use of ES2021 features (if applicable)
13+
- [ ] I've tested my code snippets in a ServiceNow environment (where possible)
14+
15+
## Repository Structure Compliance
16+
- [ ] I've placed my code snippet(s) in one of the required top-level categories:
17+
- `Core ServiceNow APIs/`
18+
- `Server-Side Components/`
19+
- `Client-Side Components/`
20+
- `Modern Development/`
21+
- `Integration/`
22+
- `Specialized Areas/`
23+
- [ ] I've used appropriate sub-categories within the top-level categories
24+
- [ ] Each code snippet has its own folder with a descriptive name
25+
26+
## Documentation
27+
- [ ] I've included a README.md file for each code snippet
28+
- [ ] The README.md includes:
29+
- Description of the code snippet functionality
30+
- Usage instructions or examples
31+
- Any prerequisites or dependencies
32+
- (Optional) Screenshots or diagrams if helpful
33+
34+
## Restrictions
35+
- [ ] My PR does not include XML exports of ServiceNow records
36+
- [ ] My PR does not contain sensitive information (passwords, API keys, tokens)
37+
- [ ] My PR does not include changes that fall outside the described scope
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/usr/bin/env node
2+
3+
const { execSync } = require('child_process');
4+
5+
const allowedCategories = new Set([
6+
'Core ServiceNow APIs',
7+
'Server-Side Components',
8+
'Client-Side Components',
9+
'Modern Development',
10+
'Integration',
11+
'Specialized Areas'
12+
]);
13+
14+
function resolveDiffRange() {
15+
if (process.argv[2]) {
16+
return process.argv[2];
17+
}
18+
19+
const inCI = process.env.GITHUB_ACTIONS === 'true';
20+
if (!inCI) {
21+
return 'origin/main...HEAD';
22+
}
23+
24+
const base = process.env.GITHUB_BASE_REF ? `origin/${process.env.GITHUB_BASE_REF}` : 'origin/main';
25+
const head = process.env.GITHUB_SHA || 'HEAD';
26+
return `${base}...${head}`;
27+
}
28+
29+
function getChangedFiles(diffRange) {
30+
let output;
31+
try {
32+
output = execSync(`git diff --name-only --diff-filter=ACMR ${diffRange}`, {
33+
encoding: 'utf8',
34+
stdio: ['ignore', 'pipe', 'pipe']
35+
});
36+
} catch (error) {
37+
console.error('Failed to collect changed files. Ensure the base branch is fetched.');
38+
console.error(error.stderr?.toString() || error.message);
39+
process.exit(1);
40+
}
41+
42+
return output
43+
.split('\n')
44+
.map((line) => line.trim())
45+
.filter(Boolean);
46+
}
47+
48+
function validateFilePath(filePath) {
49+
const normalized = filePath.replace(/\\/g, '/');
50+
const segments = normalized.split('/');
51+
52+
if (!allowedCategories.has(segments[0])) {
53+
return null;
54+
}
55+
56+
// Files must live under: Category/Subcategory/SpecificUseCase/<file>
57+
if (segments.length < 4) {
58+
return `Move '${normalized}' under a valid folder hierarchy (Category/Subcategory/Use-Case/your-file). Files directly inside '${segments[0]}' or its subcategories are not allowed.`;
59+
}
60+
61+
return null;
62+
}
63+
64+
function main() {
65+
const diffRange = resolveDiffRange();
66+
const changedFiles = getChangedFiles(diffRange);
67+
68+
if (changedFiles.length === 0) {
69+
console.log('No relevant file changes detected.');
70+
return;
71+
}
72+
73+
const problems = [];
74+
75+
for (const filePath of changedFiles) {
76+
const issue = validateFilePath(filePath);
77+
if (issue) {
78+
problems.push(issue);
79+
}
80+
}
81+
82+
if (problems.length > 0) {
83+
console.error('Folder structure violations found:');
84+
for (const msg of problems) {
85+
console.error(` - ${msg}`);
86+
}
87+
process.exit(1);
88+
}
89+
90+
console.log('Folder structure looks good.');
91+
}
92+
93+
main();

.github/templates/rootreadmetemplate.md

Lines changed: 0 additions & 40 deletions
This file was deleted.

.github/workflows/dprevent.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.

.github/workflows/hacktrack.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ on:
1414
branches: main
1515
jobs:
1616
deployment:
17+
if: github.repository == 'ServiceNowDevProgram/code-snippets'
1718
runs-on: ubuntu-latest
1819
steps:
1920
# - name: Log payload

.github/workflows/pages.yml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# GitHub Pages deployment workflow
2+
name: Deploy GitHub Pages
3+
4+
on:
5+
workflow_dispatch:
6+
7+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
8+
permissions:
9+
contents: read
10+
pages: write
11+
id-token: write
12+
13+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
14+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
15+
concurrency:
16+
group: pages-${{ github.ref }}
17+
cancel-in-progress: true
18+
19+
jobs:
20+
# Build and optimize job
21+
build:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
27+
- name: Setup Node.js
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version: '18'
31+
cache: 'npm'
32+
33+
- name: Install build dependencies
34+
run: |
35+
npm init -y
36+
npm install --save-dev html-minifier-terser clean-css-cli terser html-validate
37+
38+
- name: Validate HTML files
39+
run: |
40+
echo "Validating HTML files..."
41+
npx html-validate *.html pages/*.html || echo "HTML validation completed with warnings"
42+
43+
- name: Optimize assets
44+
run: |
45+
echo "Optimizing HTML files..."
46+
# Create backup directory
47+
mkdir -p .backup
48+
49+
# Minify HTML files (preserve original structure)
50+
find . -name "*.html" -not -path "./node_modules/*" -not -path "./.backup/*" | while read file; do
51+
echo "Minifying: $file"
52+
npx html-minifier-terser \
53+
--collapse-whitespace \
54+
--remove-comments \
55+
--remove-optional-tags \
56+
--remove-redundant-attributes \
57+
--remove-script-type-attributes \
58+
--remove-style-link-type-attributes \
59+
--minify-css \
60+
--minify-js \
61+
"$file" -o "$file.tmp" && mv "$file.tmp" "$file"
62+
done
63+
64+
# Minify CSS files if any exist
65+
if find . -name "*.css" -not -path "./node_modules/*" -not -path "./.backup/*" | grep -q .; then
66+
echo "Optimizing CSS files..."
67+
find . -name "*.css" -not -path "./node_modules/*" -not -path "./.backup/*" | while read file; do
68+
echo "Minifying: $file"
69+
npx cleancss "$file" -o "$file"
70+
done
71+
fi
72+
73+
# Remove build dependencies from final artifact
74+
rm -rf node_modules package*.json
75+
76+
- name: Setup Pages
77+
id: pages
78+
uses: actions/configure-pages@v4
79+
80+
- name: Upload artifact
81+
uses: actions/upload-pages-artifact@v3
82+
with:
83+
path: '.'
84+
85+
# Deployment job
86+
deploy:
87+
environment:
88+
name: github-pages
89+
url: ${{ steps.deployment.outputs.page_url }}
90+
runs-on: ubuntu-latest
91+
needs: build
92+
steps:
93+
- name: Deploy to GitHub Pages
94+
id: deployment
95+
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)