Skip to content

Commit

Permalink
タイトル: マージによる機能統合とバグ修正の反映 (#7)
Browse files Browse the repository at this point in the history
* Refactor setup script timeout to 20 minutes for both Ubuntu and macOS

* Refactor setup script to enable Gatekeeper

* Refactor setup script to remove Gatekeeper enablement

* Refactor setup script to handle caching and downloading HackGenNerd Font

* Refactor setup script to handle caching and downloading HackGenNerd Font in Linux environment

* Refactor setup script to handle caching and downloading HackGenNerd Font in Linux environment

* Refactor setup script to fix wget command in Linux environment

* Refactor setup script to handle caching and downloading HackGenNerd Font in Linux environment

* Refactor setup script to remove unnecessary --cask flag when installing aws-vault in Linux environment

* Refactor setup script to handle unsupported OS when installing Google Chrome

* Refactor setup script to fix cache key for HackGenNerd Font in Linux environment

* Refactor setup script to cache and download HackGenNerd Font in Linux environment

* Refactor setup script to enable Gatekeeper on macOS

* Refactor setup script to add debug mode

* Refactor setup script to fix file deletion bug in Linux environment

* Refactor setup script to download and install HackGen_NF and HackGen fonts

* Refactor setup script to cache and download HackGenNerd Font in Linux environment

* Refactor setup script to cache and download HackGenNerd Font in Linux environment

* Refactor setup script to cache and download HackGenNerd Font in Linux environment

* Refactor setup script to cache and download HackGenNerd Font in Linux environment

* Refactor setup script to conditionally download and install HackGenNerd Font in Linux environment

* Refactor setup script to use direnv hook based on the user's shell

* Refactor cache path and key for Hyper.js download

* Refactor cache path and key for Hyper.js download

* Refactor environment variable setup and cache path for Hyper.js and HackGenNerd Font

* Refactor cache path for Hyper.js download

* Refactor cache path and key for HackGenNerd Font download

* Refactor cache path and key for HackGenNerd Font and Hyper.js downloads

* Refactor cache path and key for HackGenNerd Font and Hyper.js downloads

* Refactor cache path and key for HackGenNerd Font and Hyper.js downloads

* Refactor setup script action to add execution permission and run the script

* Add Python version 3.12.1 to .python-version file

* Refactor generate PR description workflow

* Refactor generate PR workflow to trigger only on pull requests opened or edited in the main branch

* Refactor generate PR workflow to trigger only on pull requests opened or edited in the main branch

* Refactor generate PR workflow to install uv dependency with pip

* Refactor .editorconfig to set indent size for Python files

* Refactor generate PR workflow to update PR description generation script location

* Refactor generate PR workflow to update PR description generation script location, install uv dependency with pip, and trigger only on pull requests opened or edited in the main branch. Also, add requirements.txt file with openai==1.52.1 dependency.

* Refactor generate PR workflow to update PR description generation script location, install uv dependency with pip, and trigger only on pull requests opened or edited in the main branch. Also, add requirements.txt file with openai==1.52.1 dependency.

* Refactor generate PR workflow to enable caching of uv packages

* Refactor generate PR workflow to remove uv package caching

* Refactor setup.sh to install necessary packages for pyenv 3.12.1 on Linux and macOS

* Refactor setup.sh to install necessary packages for pyenv 3.12.1 on Linux and macOS, and add installation of local utility packages

* Refactor setup.sh to conditionally clone anyenv if it doesn't exist

* Refactor setup.sh to clone anyenv if it doesn't exist

* Refactor setup.sh to conditionally clone anyenv if it doesn't exist and force initialization

* Refactor setup.sh to add .config/git/ignore to dotfiles

* Refactor setup.sh to install necessary packages for pyenv 3.12.1 on Linux and macOS, and add installation of local utility packages

* Refactor setup.sh to remove unnecessary GUI application installation check and add CI environment check

* Refactor setup.sh to fix CI environment check and variable assignment

* Refactor default setup script name in GitHub Actions workflow

* Refactor setup.sh to add .config/git/ignore to dotfiles

* Refactor setup.sh to remove unnecessary GUI application installation check and add CI environment check

* Refactor setup.sh to remove unnecessary GUI application installation check and add CI environment check

* Refactor setup.sh to fix HackGenNerd Font installation check and add installation attempt

* Refactor setup.sh to update package manager and install libcrypt-dev

* Add pyproject.toml with project metadata and dependencies

* Update pyproject.toml with openai dependency

* Update workflow to install dependencies with uv

* Update workflow to install dependencies with uv

* Update workflow to install dependencies with uv

* Update workflow to grant write permissions for pull requests

* Update setup script to remove unnecessary dotfile

* Refactor setup script to handle CI environment

* Refactor setup script to handle CI environment and remove unnecessary dotfile

* Refactor setup script to update file paths for dotfiles

* Refactor setup script to update file paths for dotfiles

* Refactor setup script to handle CI environment and update file paths for dotfiles

* Refactor setup script to update file paths for dotfiles

* Refactor setup script to update file paths for dotfiles and handle CI environment

* Refactor setup script to update file paths for dotfiles

* Refactor setup script to update file paths for dotfiles and switch to main branch before pulling changes

* Refactor setup script to update file paths for dotfiles and handle CI environment

* Refactor setup script to update file paths for dotfiles and remove unnecessary branch switch

* Refactor setup script to remove unnecessary branch switch and update file paths for dotfiles

* Refactor setup script to update file paths for dotfiles and handle application installations

* Refactor setup script to update file paths for dotfiles and handle CI environment

* Refactor setup script to update OpenAI API key retrieval method

* Refactor setup script to update file paths for dotfiles and remove unnecessary branch switch

* Refactor setup script to import the 'os' module for environment variable retrieval

* Refactor setup script to use OpenAI Python package and update API key retrieval method

* Refactor setup script to use OpenAI Python package and update API key retrieval method

* Refactor setup script to fetch latest changes from origin and get diff between origin/main and current branch

* Refactor setup script to update OpenAI Python package model and API key retrieval method

* Refactor setup script to update OpenAI Python package model and API key retrieval method

* Refactor setup script to update OpenAI Python package model and API key retrieval method

* Refactor setup script to update OpenAI Python package model and API key retrieval method

* Refactor setup script to import subprocess module for command execution

* Refactor setup script to import subprocess module for command execution and update OpenAI Python package model and API key retrieval method

* Refactor setup script to update OpenAI Python package model and API key retrieval method

* Refactor setup script to update OpenAI Python package model and API key retrieval method

* Refactor setup script to update OpenAI Python package model and API key retrieval method

* Refactor setup script to update OpenAI Python package model and API key retrieval method

* Refactor generate_pr_description.py to update response parsing method

* Refactor generate_pr_description.py to limit the number of commit logs retrieved

* Refactor generate_pr_description.py to update response parsing method

* Refactor generate_pr_description.py to limit the number of commit logs retrieved

* Refactor generate_pr_description.py to increase max_tokens for prompt generation

* Refactor generate_pr_description.py to increase max_tokens for prompt generation

* Refactor generate_pr_description.py to fetch remote changes before retrieving commit logs
  • Loading branch information
tqer39 authored Oct 25, 2024
1 parent 1a8998d commit a9b7cb5
Show file tree
Hide file tree
Showing 12 changed files with 728 additions and 108 deletions.
2 changes: 1 addition & 1 deletion .bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export PATH="$HOME/.anyenv/bin:$PATH"
eval "$(anyenv init -)"

# direnv
eval "$(direnv hook zsh)"
eval "$(direnv hook bash)"

# pbcopy/pbpaste
if command -v xsel &> /dev/null; then
Expand Down
81 changes: 81 additions & 0 deletions .config/git/ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Created by https://www.toptal.com/developers/gitignore/api/windows,macos,linux
# Edit at https://www.toptal.com/developers/gitignore?templates=windows,macos,linux

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

# End of https://www.toptal.com/developers/gitignore/api/windows,macos,linux

# customize
tmp/
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ trim_trailing_whitespace = true

[*.sh]
indent_size = 4

[*.py]
indent_size = 4
3 changes: 2 additions & 1 deletion .github/actions/setup-script/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: Runs the setup script and performs checks
inputs:
script:
description: 'The setup script to run'
default: 'setup.sh'
default: 'setup'
required: true

runs:
Expand All @@ -15,6 +15,7 @@ runs:
- name: 実行権限を設定
run: chmod +x ${{ inputs.script }}
shell: bash

- name: セットアップスクリプトを実行
run: ./${{ inputs.script }}
shell: bash
50 changes: 50 additions & 0 deletions .github/workflows/generate-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
name: Generate PR Description

on:
pull_request:
branches:
- main

jobs:
generate-pr-description:
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5

- name: pip upgrade
run: |
python -m pip install --upgrade pip
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
version: "0.4.26"
enable-cache: true
cache-dependency-glob: "requirements**.txt"

- name: Install dependencies with uv
run: |
uv pip install -r requirements.txt --system
- name: Generate PR Title and Description
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
python .github/workflows/scripts/generate_pr_description.py > pr_output.txt
cat pr_output.txt
- name: Update PR Title and Description
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
PR_TITLE=$(head -n 1 pr_output.txt)
PR_BODY=$(tail -n +2 pr_output.txt)
gh pr edit $PR_NUMBER --title "$PR_TITLE" --body "$PR_BODY"
74 changes: 74 additions & 0 deletions .github/workflows/scripts/generate_pr_description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
from openai import OpenAI
import os
import subprocess

# OpenAI API キーを設定
api_key = os.getenv("OPENAI_API_KEY")
if not api_key:
raise ValueError("API key is not set.")

client = OpenAI(
# This is the default and can be omitted
api_key = os.getenv("OPENAI_API_KEY")
)

# プロンプトの準備
def create_prompt(commit_logs):
return f"""
以下のコミットログとファイルの差分を読んで、わかりやすいプルリクエストのタイトルと詳細な説明を日本語で作成してください。
コミットログとファイルの差分:
{commit_logs}
出力形式:
タイトル: プルリクエストのタイトル
説明:
- 変更点の概要
- 技術的な詳細や注意点
"""

# OpenAI API でのリクエスト
def generate_pr_description(commit_logs):
prompt = create_prompt(commit_logs)

response = client.chat.completions.create(
model="gpt-4o", # GPT-3.5の場合は "gpt-3.5-turbo" に変更
messages=[
{"role": "system", "content": "あなたは優秀なソフトウェアエンジニアです。"},
{"role": "user", "content": prompt},
],
max_tokens=1000,
temperature=0.1,
)

return response.choices[0].message.content.strip()

# Git コミットログとファイルの差分の取得
def get_commit_logs_and_diffs():
# リモートの変更を取得
subprocess.run(['git', 'fetch', 'origin'], check=True)

result = subprocess.run(['git', 'log', '--pretty=format:%H %s', 'origin/main..HEAD', '-n', '70'], capture_output=True, text=True) # コミットログの数を制限
commit_logs = result.stdout.strip().split('\n')

if not commit_logs or commit_logs == ['']:
return ""

logs_and_diffs = []
for commit in commit_logs:
commit_hash = commit.split()[0]
if commit_hash:
diff_result = subprocess.run(['git', 'diff', commit_hash + '^!', '--'], capture_output=True, text=True)
logs_and_diffs.append(f"Commit: {commit}\nDiff:\n{diff_result.stdout}")

return "\n\n".join(logs_and_diffs)

# メインロジック
if __name__ == "__main__":
commit_logs_and_diffs = get_commit_logs_and_diffs()

if commit_logs_and_diffs:
pr_description = generate_pr_description(commit_logs_and_diffs)
print(pr_description)
else:
print("No new commits detected.")
92 changes: 84 additions & 8 deletions .github/workflows/test-setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,128 @@ on:
push:
branches:
- main
pull_request:
branches:
- main
# pull_request:
# branches:
# - main
workflow_dispatch:

env:
HACKGEN_VERSION: "2.9.0"
DL_PATH: "$HOME/Downloads"
HACKGEN_VERSION: "2.9.0"
HYPER_VERSION: "3.4.1"

jobs:
test-ubuntu:
timeout-minutes: 20
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up environment variables
run: |
echo "DL_PATH=$HOME/Downloads" >> $GITHUB_ENV
echo "HACKGEN_VERSION=2.9.0" >> $GITHUB_ENV
echo "HYPER_VERSION=3.4.1" >> $GITHUB_ENV
- name: Cache HackGenNerd Font
id: cache-hackgen-nf
uses: actions/cache@v4
with:
path: ${{ env.DL_PATH }}/HackGen_NF_v${{ env.HACKGEN_VERSION }}.zip
key: ${{ runner.os }}-hackgen-nf-${{ env.HACKGEN_VERSION }}
key: ${{ runner.os }}-hackgen-nf-${{ env.HACKGEN_VERSION }}-
restore-keys: |
${{ runner.os }}-hackgen-nf-${{ env.HACKGEN_VERSION }}
${{ runner.os }}-hackgen-nf-${{ env.HACKGEN_VERSION }}-
- name: Download HackGenNerd Font
if: steps.cache-hackgen-nf.outputs.cache-hit != 'true'
run: |
wget -P "${{ env.DL_PATH }}" "https://github.com/yuru7/HackGen/releases/download/v${{ env.HACKGEN_VERSION }}/HackGen_NF_v${{ env.HACKGEN_VERSION }}.zip"
- name: Cache HackGen
id: cache-hackgen
uses: actions/cache@v4
with:
path: ${{ env.DL_PATH }}/HackGen_v${{ env.HACKGEN_VERSION }}.zip
key: ${{ runner.os }}-hackgen-${{ env.HACKGEN_VERSION }}
key: ${{ runner.os }}-hackgen-${{ env.HACKGEN_VERSION }}-
restore-keys: |
${{ runner.os }}-hackgen-${{ env.HACKGEN_VERSION }}
${{ runner.os }}-hackgen-${{ env.HACKGEN_VERSION }}-
- name: Download HackGen
if: steps.cache-hackgen.outputs.cache-hit != 'true'
run: |
wget -P "${{ env.DL_PATH }}" "https://github.com/yuru7/HackGen/releases/download/v${{ env.HACKGEN_VERSION }}/HackGen_v${{ env.HACKGEN_VERSION }}.zip"
- name: Cache Hyper.js
id: cache-hyper
uses: actions/cache@v4
with:
path: ${{ env.DL_PATH }}/deb
key: ${{ runner.os }}-hyper-js-${{ env.HYPER_VERSION }}-
restore-keys: |
${{ runner.os }}-hyper-js-${{ env.HYPER_VERSION }}-
- name: Download Hyper.js
if: steps.cache-hyper.outputs.cache-hit != 'true'
run: |
wget -P "${{ env.DL_PATH }}" "https://releases.hyper.is/download/deb"
- uses: ./.github/actions/setup-script

test-macos:
timeout-minutes: 20
runs-on: macos-latest
steps:
- uses: actions/checkout@v4

- name: Set up environment variables
run: |
echo "DL_PATH=$HOME/Downloads" >> $GITHUB_ENV
echo "HACKGEN_VERSION=2.9.0" >> $GITHUB_ENV
echo "HYPER_VERSION=3.4.1" >> $GITHUB_ENV
- name: Cache HackGenNerd Font
id: cache-hackgen-nf
uses: actions/cache@v4
with:
path: ${{ env.DL_PATH }}/HackGen_NF_v${{ env.HACKGEN_VERSION }}.zip
key: ${{ runner.os }}-hackgen-nf-${{ env.HACKGEN_VERSION }}-
restore-keys: |
${{ runner.os }}-hackgen-nf-${{ env.HACKGEN_VERSION }}-
- name: Download HackGenNerd Font
if: steps.cache-hackgen-nf.outputs.cache-hit != 'true'
run: |
wget -P "${{ env.DL_PATH }}" "https://github.com/yuru7/HackGen/releases/download/v${{ env.HACKGEN_VERSION }}/HackGen_NF_v${{ env.HACKGEN_VERSION }}.zip"
- name: Cache HackGen
id: cache-hackgen
uses: actions/cache@v4
with:
path: ${{ env.DL_PATH }}/HackGen_v${{ env.HACKGEN_VERSION }}.zip
key: ${{ runner.os }}-hackgen-${{ env.HACKGEN_VERSION }}-
restore-keys: |
${{ runner.os }}-hackgen-${{ env.HACKGEN_VERSION }}-
- name: Download HackGen
if: steps.cache-hackgen.outputs.cache-hit != 'true'
run: |
wget -P "${{ env.DL_PATH }}" "https://github.com/yuru7/HackGen/releases/download/v${{ env.HACKGEN_VERSION }}/HackGen_v${{ env.HACKGEN_VERSION }}.zip"
- name: Cache Hyper.js
id: cache-hyper
uses: actions/cache@v4
with:
path: ${{ env.DL_PATH }}/deb
key: ${{ runner.os }}-hyper-js-${{ env.HYPER_VERSION }}-
restore-keys: |
${{ runner.os }}-hyper-js-${{ env.HYPER_VERSION }}-
- name: Download Hyper.js
if: steps.cache-hyper.outputs.cache-hit != 'true'
run: |
wget -P "${{ env.DL_PATH }}" "https://releases.hyper.is/download/deb"
- name: Enable Gatekeeper
run: sudo spctl --master-enable

- uses: ./.github/actions/setup-script
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12.1
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[project]
name = "local-workspace-provisioning"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"openai==1.52.1",
]
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
openai==1.52.1
Loading

0 comments on commit a9b7cb5

Please sign in to comment.