improve ui
This commit is contained in:
@@ -1,15 +1,20 @@
|
||||
# Add New Prompt
|
||||
|
||||
You'll need to add your prompt into README.md, and to the `prompts.csv` file. If your prompt includes quotes, you will need to double-quote them to escape in CSV file.
|
||||
You'll need to add your prompt into README.md, and to the `prompts.csv` file. If
|
||||
your prompt includes quotes, you will need to double-quote them to escape in CSV
|
||||
file.
|
||||
|
||||
If the prompt is generated by AI, please add `<mark>Generated by AI</mark>` to the end of the contribution line.
|
||||
If the prompt is generated by AI, please add `<mark>Generated by AI</mark>` to
|
||||
the end of the contribution line.
|
||||
|
||||
- [ ] I've confirmed the prompt works well
|
||||
- [ ] I've added `Contributed by: [@yourusername](https://github.com/yourusername)`
|
||||
- [ ] I've added
|
||||
`Contributed by: [@yourusername](https://github.com/yourusername)`
|
||||
- [ ] I've added to the README.md
|
||||
- [ ] I've added to the `prompts.csv`
|
||||
- [ ] Escaped quotes by double-quoting them
|
||||
- [ ] No spaces after commas after double quotes. e.g. `"Hello","hi"`, not `"Hello", "hi"`
|
||||
- [ ] No spaces after commas after double quotes. e.g. `"Hello","hi"`, not
|
||||
`"Hello", "hi"`
|
||||
- [ ] Removed "Act as" from the title on CSV
|
||||
|
||||
Please make sure you've completed all the checklist.
|
||||
|
||||
@@ -33,7 +33,7 @@ jobs:
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: '18'
|
||||
node-version: "18"
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm install openai@^4.0.0 @octokit/rest@^19.0.0
|
||||
@@ -52,7 +52,7 @@ jobs:
|
||||
const openai = new OpenAI({
|
||||
apiKey: process.env.OPENAI_API_KEY
|
||||
});
|
||||
|
||||
|
||||
const octokit = new Octokit({
|
||||
auth: process.env.GH_TOKEN
|
||||
});
|
||||
@@ -60,7 +60,7 @@ jobs:
|
||||
const eventName = process.env.GITHUB_EVENT_NAME;
|
||||
const eventPath = process.env.GITHUB_EVENT_PATH;
|
||||
const event = require(eventPath);
|
||||
|
||||
|
||||
// Double check user authorization
|
||||
const actor = event.sender?.login || event.pull_request?.user?.login || event.issue?.user?.login;
|
||||
if (actor !== 'f') {
|
||||
@@ -72,7 +72,7 @@ jobs:
|
||||
let command = '';
|
||||
let issueNumber = null;
|
||||
let isPullRequest = false;
|
||||
|
||||
|
||||
if (eventName === 'issues') {
|
||||
command = event.issue.body;
|
||||
issueNumber = event.issue.number;
|
||||
@@ -96,7 +96,7 @@ jobs:
|
||||
|
||||
// Extract the actual command after /ai
|
||||
const aiCommand = command.substring(3).trim();
|
||||
|
||||
|
||||
// Handle resolve conflicts command
|
||||
if (aiCommand === 'resolve' || aiCommand === 'fix conflicts') {
|
||||
if (!isPullRequest) {
|
||||
@@ -112,7 +112,7 @@ jobs:
|
||||
|
||||
try {
|
||||
console.log('Starting resolve command execution...');
|
||||
|
||||
|
||||
// Get PR details
|
||||
console.log('Fetching PR details...');
|
||||
const { data: pr } = await octokit.pulls.get({
|
||||
@@ -140,7 +140,7 @@ jobs:
|
||||
title = title.trim();
|
||||
// Remove "Act as" or "Act as a" or "Act as an" from start if present
|
||||
title = title.replace(/^Act as (?:a |an )?/i, '');
|
||||
|
||||
|
||||
// Capitalize each word except common articles and prepositions
|
||||
const lowercaseWords = ['a', 'an', 'the', 'and', 'but', 'or', 'for', 'nor', 'on', 'at', 'to', 'for', 'with', 'in'];
|
||||
const capitalized = title.toLowerCase().split(' ').map((word, index) => {
|
||||
@@ -150,7 +150,7 @@ jobs:
|
||||
}
|
||||
return word;
|
||||
}).join(' ');
|
||||
|
||||
|
||||
// Add "Act as" prefix
|
||||
return `Act as ${capitalized}`;
|
||||
};
|
||||
@@ -168,17 +168,17 @@ jobs:
|
||||
|
||||
console.log('Attempting to extract prompts from README changes...');
|
||||
const promptMatches = [...addedLines.matchAll(/## (?:Act as (?:a |an )?)?([^\n]+)\n(?:Contributed by:[^\n]*\n)?(?:> )?([^#]+?)(?=\n##|\n\n##|$)/ig)];
|
||||
|
||||
|
||||
for (const match of promptMatches) {
|
||||
const actName = normalizeTitle(match[1]);
|
||||
const promptText = match[2].trim()
|
||||
.replace(/^(?:Contributed by:?[^\n]*\n\s*)+/i, '')
|
||||
.trim();
|
||||
const contributorLine = addedLines.match(/Contributed by: \[@([^\]]+)\]\(https:\/\/github\.com\/([^\)]+)\)/);
|
||||
const contributorInfo = contributorLine
|
||||
const contributorInfo = contributorLine
|
||||
? `Contributed by: [@${contributorLine[1]}](https://github.com/${contributorLine[2]})`
|
||||
: `Contributed by: [@${pr.user.login}](https://github.com/${pr.user.login})`;
|
||||
|
||||
|
||||
prompts.set(actName.toLowerCase(), { actName, promptText, contributorInfo });
|
||||
console.log(`Found prompt in README: "${actName}"`);
|
||||
foundInReadme = true;
|
||||
@@ -206,7 +206,7 @@ jobs:
|
||||
const promptText = matches[1][1].replace(/""/g, '"').trim()
|
||||
.replace(/^(?:Contributed by:?[^\n]*\n\s*)+/i, '')
|
||||
.trim();
|
||||
|
||||
|
||||
const contributorInfo = `Contributed by: [@${pr.user.login}](https://github.com/${pr.user.login})`;
|
||||
prompts.set(actName.toLowerCase(), { actName, promptText, contributorInfo });
|
||||
console.log(`Found prompt in CSV: "${actName}"`);
|
||||
@@ -256,16 +256,16 @@ jobs:
|
||||
for (const { actName, promptText, contributorInfo } of promptsArray) {
|
||||
// Remove markdown quote character and trim whitespace
|
||||
const cleanPrompt = promptText.replace(/^>\s*/gm, '').trim();
|
||||
|
||||
|
||||
// For README: Add quote to each line
|
||||
const readmePrompt = cleanPrompt.split('\n')
|
||||
.map(line => `> ${line.trim()}`)
|
||||
.join('\n');
|
||||
const newSection = `## ${actName}\n${contributorInfo}\n\n${readmePrompt}\n\n`;
|
||||
|
||||
|
||||
// For CSV: Convert to single paragraph
|
||||
const csvPrompt = cleanPrompt.replace(/\n+/g, ' ').trim();
|
||||
|
||||
|
||||
// Insert the new section before Contributors in README
|
||||
const contributorsIndex = readmeContent.indexOf('## Contributors');
|
||||
if (contributorsIndex === -1) {
|
||||
@@ -483,13 +483,13 @@ jobs:
|
||||
if (file.status === 'removed') {
|
||||
return `Deleted: ${file.filename}`;
|
||||
}
|
||||
|
||||
|
||||
// Get file content for added or modified files
|
||||
if (file.status === 'added' || file.status === 'modified') {
|
||||
const patch = file.patch || '';
|
||||
return `${file.status === 'added' ? 'Added' : 'Modified'}: ${file.filename}\nChanges:\n${patch}`;
|
||||
}
|
||||
|
||||
|
||||
return `${file.status}: ${file.filename}`;
|
||||
}));
|
||||
|
||||
@@ -551,7 +551,7 @@ jobs:
|
||||
// If response contains code changes, create a new branch and PR
|
||||
if (response.includes('```')) {
|
||||
const branchName = `ai-bot/fix-${issueNumber}`;
|
||||
|
||||
|
||||
// Create new branch
|
||||
const defaultBranch = event.repository.default_branch;
|
||||
const ref = await octokit.git.getRef({
|
||||
@@ -559,7 +559,7 @@ jobs:
|
||||
repo: event.repository.name,
|
||||
ref: `heads/${defaultBranch}`
|
||||
});
|
||||
|
||||
|
||||
await octokit.git.createRef({
|
||||
owner: event.repository.owner.login,
|
||||
repo: event.repository.name,
|
||||
@@ -572,7 +572,7 @@ jobs:
|
||||
for (const block of codeBlocks) {
|
||||
const [_, filePath, ...codeLines] = block.split('\n');
|
||||
const content = Buffer.from(codeLines.join('\n')).toString('base64');
|
||||
|
||||
|
||||
await octokit.repos.createOrUpdateFileContents({
|
||||
owner: event.repository.owner.login,
|
||||
repo: event.repository.name,
|
||||
@@ -620,4 +620,4 @@ jobs:
|
||||
repo: context.repo.repo,
|
||||
issue_number: issueNumber,
|
||||
body: '❌ Sorry, there was an error processing your command. Please try again or contact the repository maintainers.'
|
||||
});
|
||||
});
|
||||
|
||||
@@ -19,7 +19,7 @@ jobs:
|
||||
with:
|
||||
script: |
|
||||
const pr = context.payload.pull_request;
|
||||
|
||||
|
||||
// Check if PR has conflicts
|
||||
if (pr.mergeable === false) {
|
||||
console.log('PR has conflicts, commenting /ai resolve');
|
||||
@@ -30,7 +30,7 @@ jobs:
|
||||
body: '/ai resolve'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Check if PR title starts with "updated"
|
||||
if (pr.title.toLowerCase().startsWith('updated')) {
|
||||
console.log('PR title starts with "updated", commenting /ai suggest title');
|
||||
@@ -40,4 +40,4 @@ jobs:
|
||||
issue_number: pr.number,
|
||||
body: '/ai suggest title'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,70 +8,70 @@ jobs:
|
||||
lint_and_check_trailing_whitespaces:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: '3.8'
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
python -m pip install csvkit
|
||||
|
||||
- name: Validate CSV structure
|
||||
run: |
|
||||
echo "Checking CSV structure..."
|
||||
if ! csvclean -n prompts.csv 2>&1 | tee /tmp/csv_errors.log; then
|
||||
echo "::error::CSV validation failed"
|
||||
cat /tmp/csv_errors.log
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Check CSV format
|
||||
run: |
|
||||
echo "Checking CSV format..."
|
||||
if ! python -c '
|
||||
import csv
|
||||
with open("prompts.csv", "r", encoding="utf-8") as f:
|
||||
reader = csv.reader(f)
|
||||
headers = next(reader)
|
||||
if headers != ["act", "prompt"]:
|
||||
print("Error: CSV headers must be exactly [act, prompt]")
|
||||
exit(1)
|
||||
for row_num, row in enumerate(reader, 2):
|
||||
if len(row) != 2:
|
||||
print(f"Error: Row {row_num} has {len(row)} columns, expected 2")
|
||||
exit(1)
|
||||
if not row[0] or not row[1]:
|
||||
print(f"Error: Row {row_num} has empty values")
|
||||
exit(1)
|
||||
'; then
|
||||
echo "::error::CSV format check failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Check Trailing Whitespaces
|
||||
run: |
|
||||
echo "Checking for trailing whitespaces..."
|
||||
if grep -q "[[:space:]]$" prompts.csv; then
|
||||
echo "::error::Found trailing whitespaces in prompts.csv"
|
||||
grep -n "[[:space:]]$" prompts.csv | while read -r line; do
|
||||
echo "Line with trailing whitespace: $line"
|
||||
done
|
||||
exit 1
|
||||
fi
|
||||
echo "No trailing whitespaces found"
|
||||
|
||||
- name: Check for UTF-8 BOM and line endings
|
||||
run: |
|
||||
echo "Checking for UTF-8 BOM and line endings..."
|
||||
if file prompts.csv | grep -q "with BOM"; then
|
||||
echo "::error::File contains UTF-8 BOM marker"
|
||||
exit 1
|
||||
fi
|
||||
if file prompts.csv | grep -q "CRLF"; then
|
||||
echo "::error::File contains Windows-style (CRLF) line endings"
|
||||
exit 1
|
||||
fi
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: "3.8"
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
python -m pip install csvkit
|
||||
|
||||
- name: Validate CSV structure
|
||||
run: |
|
||||
echo "Checking CSV structure..."
|
||||
if ! csvclean -n prompts.csv 2>&1 | tee /tmp/csv_errors.log; then
|
||||
echo "::error::CSV validation failed"
|
||||
cat /tmp/csv_errors.log
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Check CSV format
|
||||
run: |
|
||||
echo "Checking CSV format..."
|
||||
if ! python -c '
|
||||
import csv
|
||||
with open("prompts.csv", "r", encoding="utf-8") as f:
|
||||
reader = csv.reader(f)
|
||||
headers = next(reader)
|
||||
if headers != ["act", "prompt"]:
|
||||
print("Error: CSV headers must be exactly [act, prompt]")
|
||||
exit(1)
|
||||
for row_num, row in enumerate(reader, 2):
|
||||
if len(row) != 2:
|
||||
print(f"Error: Row {row_num} has {len(row)} columns, expected 2")
|
||||
exit(1)
|
||||
if not row[0] or not row[1]:
|
||||
print(f"Error: Row {row_num} has empty values")
|
||||
exit(1)
|
||||
'; then
|
||||
echo "::error::CSV format check failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Check Trailing Whitespaces
|
||||
run: |
|
||||
echo "Checking for trailing whitespaces..."
|
||||
if grep -q "[[:space:]]$" prompts.csv; then
|
||||
echo "::error::Found trailing whitespaces in prompts.csv"
|
||||
grep -n "[[:space:]]$" prompts.csv | while read -r line; do
|
||||
echo "Line with trailing whitespace: $line"
|
||||
done
|
||||
exit 1
|
||||
fi
|
||||
echo "No trailing whitespaces found"
|
||||
|
||||
- name: Check for UTF-8 BOM and line endings
|
||||
run: |
|
||||
echo "Checking for UTF-8 BOM and line endings..."
|
||||
if file prompts.csv | grep -q "with BOM"; then
|
||||
echo "::error::File contains UTF-8 BOM marker"
|
||||
exit 1
|
||||
fi
|
||||
if file prompts.csv | grep -q "CRLF"; then
|
||||
echo "::error::File contains Windows-style (CRLF) line endings"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -16,7 +16,7 @@ jobs:
|
||||
- name: Set up Ruby
|
||||
uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: '3.2'
|
||||
ruby-version: "3.2"
|
||||
bundler-cache: true # This will cache dependencies
|
||||
|
||||
- name: Update Bundler
|
||||
|
||||
Reference in New Issue
Block a user