diff --git a/generated_file_0.js b/generated_file_0.js new file mode 100644 index 000000000..6e59bcc6f --- /dev/null +++ b/generated_file_0.js @@ -0,0 +1,24 @@ +// MODIFY: react-frontend/src/api/fetchData.js +import axios from 'axios'; + +const apiBaseUrl = process.env.REACT_APP_API_BASE_URL || 'http://localhost:8080/api'; + +export const fetchData = async (endpoint) => { + try { + const response = await axios.get(`${apiBaseUrl}/${endpoint}`); + return response.data; + } catch (error) { + console.error('Error fetching data:', error); + throw error; + } +}; + +export const postData = async (endpoint, data) => { + try { + const response = await axios.post(`${apiBaseUrl}/${endpoint}`, data); + return response.data; + } catch (error) { + console.error('Error posting data:', error); + throw error; + } +}; \ No newline at end of file diff --git a/generated_file_0.json b/generated_file_0.json new file mode 100644 index 000000000..e53390252 --- /dev/null +++ b/generated_file_0.json @@ -0,0 +1,30 @@ +# Configuration section improvement for security and flexibility +REPO_URL="https://api.github.com/repos/${OWNER}/${REPO}" +GITHUB_TOKEN="${GITHUB_TOKEN?Error: GITHUB_TOKEN is not set}" + +# Improved error handling for git commands +create_branch() { + echo "Creating and switching to new branch: $BRANCH_NAME" + git checkout -b $BRANCH_NAME || { echo "Failed to create new branch"; exit 1; } + git add . || { echo "Failed to add changes"; exit 1; } + git commit -m "Initial commit for feature development" || { echo "Failed to commit changes"; exit 1; } + git push origin $BRANCH_NAME || { echo "Failed to push branch"; exit 1; } +} + +# Use environment variable for GitHub token and improve JSON payload +create_pull_request() { + echo "Creating pull request..." + response=$(curl -s -X POST -H "Authorization: token $GITHUB_TOKEN" \ + -d "{\"title\": \"Pull Request for $BRANCH_NAME\", \"body\": \"This PR includes changes from the $BRANCH_NAME branch.\", \"head\": \"$BRANCH_NAME\", \"base\": \"$MAIN_BRANCH\"}" \ + $REPO_URL/pulls) + + if echo "$response" | jq -e .id > /dev/null; then + pr_url=$(echo "$response" | jq -r .html_url) + echo "Pull request created successfully: $pr_url" + else + echo "Failed to create pull request: $(echo "$response" | jq -r .message)" + exit 1 + fi +} + +# Additional improvements may include better input and environment variable validation, and potentially integrating with external configuration files or secure storage mechanisms for sensitive information like tokens. \ No newline at end of file diff --git a/generated_file_1.json b/generated_file_1.json new file mode 100644 index 000000000..b8323b534 --- /dev/null +++ b/generated_file_1.json @@ -0,0 +1,8 @@ +// ADD to spring-backend/src/main/java/com/example/controller/NewFeatureController.java +import javax.validation.Valid; + +@GetMapping +public ResponseEntity> getAllFeatures() { + List features = newFeatureService.findAllFeatures(); + return ResponseEntity.ok().body(features); +} \ No newline at end of file diff --git a/generated_file_2.json b/generated_file_2.json new file mode 100644 index 000000000..7b3cd335d --- /dev/null +++ b/generated_file_2.json @@ -0,0 +1,4 @@ +// MODIFY: spring-backend/src/main/java/com/example/service/NewFeatureService.java +public List findAllFeatures() { + return newFeatureRepository.findAll(PageRequest.of(0, 10)).getContent(); +} \ No newline at end of file diff --git "a/react-frontend/src/api/fetchData.js\n```javascript\nimport axios from 'axios';\n\nconst apiBaseUrl = process.env.REACT_APP_API_BASE_URL __ 'http_/localhost_8080/api';\n\nexport const fetchData = async (endpoint) =_ {\n try {\n const response = await axios.get(`${apiBaseUrl}/${endpoint}`);\n return response.data;\n } catch (error) {\n console.error('Error fetching data_', error);\n throw error;\n }\n};\n\nexport const postData = async (endpoint, data) =_ {\n try {\n const response = await axios.post(`${apiBaseUrl}/${endpoint}`, data);\n return response.data;\n } catch (error) {\n console.error('Error posting data_', error);\n throw error;\n }\n};" "b/react-frontend/src/api/fetchData.js\n```javascript\nimport axios from 'axios';\n\nconst apiBaseUrl = process.env.REACT_APP_API_BASE_URL __ 'http_/localhost_8080/api';\n\nexport const fetchData = async (endpoint) =_ {\n try {\n const response = await axios.get(`${apiBaseUrl}/${endpoint}`);\n return response.data;\n } catch (error) {\n console.error('Error fetching data_', error);\n throw error;\n }\n};\n\nexport const postData = async (endpoint, data) =_ {\n try {\n const response = await axios.post(`${apiBaseUrl}/${endpoint}`, data);\n return response.data;\n } catch (error) {\n console.error('Error posting data_', error);\n throw error;\n }\n};" new file mode 100644 index 000000000..cbff8c609 --- /dev/null +++ "b/react-frontend/src/api/fetchData.js\n```javascript\nimport axios from 'axios';\n\nconst apiBaseUrl = process.env.REACT_APP_API_BASE_URL __ 'http_/localhost_8080/api';\n\nexport const fetchData = async (endpoint) =_ {\n try {\n const response = await axios.get(`${apiBaseUrl}/${endpoint}`);\n return response.data;\n } catch (error) {\n console.error('Error fetching data_', error);\n throw error;\n }\n};\n\nexport const postData = async (endpoint, data) =_ {\n try {\n const response = await axios.post(`${apiBaseUrl}/${endpoint}`, data);\n return response.data;\n } catch (error) {\n console.error('Error posting data_', error);\n throw error;\n }\n};" @@ -0,0 +1 @@ +FILE_OPERATION: CREATE react-frontend/src/components/NewFeatureComponent.js \ No newline at end of file diff --git a/scripts/manage_pull_request.sh b/scripts/manage_pull_request.sh new file mode 100644 index 000000000..64e962337 --- /dev/null +++ b/scripts/manage_pull_request.sh @@ -0,0 +1,60 @@ +bash +#!/bin/bash + +# Script to automate the creation and management of pull requests + +# Ensure the script is executed from the root of the repository +if [ ! -f "package.json" ] && [ ! -f "pom.xml" ]; then + echo "Please run this script from the root of the project directory." + exit 1 +fi + +# Check for necessary command-line tools +for cmd in git jq; do + if ! command -v $cmd &> /dev/null; then + echo "$cmd is required but not installed. Aborting." + exit 1 + fi +done + +# Configuration +REPO_URL="https://api.github.com/repos//" +BRANCH_NAME="feature/$(date +%Y%m%d%H%M%S)" +MAIN_BRANCH="main" + +# Function to create a new branch and push changes +create_branch() { + echo "Creating and switching to new branch: $BRANCH_NAME" + git checkout -b $BRANCH_NAME + git add . + git commit -m "Initial commit for feature development" + git push origin $BRANCH_NAME +} + +# Function to create a pull request +create_pull_request() { + echo "Creating pull request..." + response=$(curl -s -X POST -H "Authorization: token " \ + -d "{"title":"Pull Request for $BRANCH_NAME","body":"This PR includes changes from the $BRANCH_NAME branch.","head":"$BRANCH_NAME","base":"$MAIN_BRANCH"}" \ + $REPO_URL/pulls) + + if echo "$response" | jq -e .id > /dev/null; then + pr_url=$(echo "$response" | jq -r .html_url) + echo "Pull request created successfully: $pr_url" + else + echo "Failed to create pull request: $(echo "$response" | jq -r .message)" + exit 1 + fi +} + +# Function to review pull requests +review_pull_request() { + echo "Reviewing pull request..." + # Implement review logic here or integrate with a CI/CD pipeline + # This is a placeholder for detailed review logic +} + +# Main script execution +create_branch +create_pull_request +review_pull_request \ No newline at end of file diff --git a/spring-backend/src/main/java/com/example/controller/NewFeatureController.java b/spring-backend/src/main/java/com/example/controller/NewFeatureController.java new file mode 100644 index 000000000..00a77a7e4 --- /dev/null +++ b/spring-backend/src/main/java/com/example/controller/NewFeatureController.java @@ -0,0 +1,22 @@ +java +package com.example.controller; + +import com.example.service.NewFeatureService; +import com.example.model.NewFeature; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/api/new-feature-endpoint") +public class NewFeatureController { + + @Autowired + private NewFeatureService newFeatureService; + + @GetMapping + public List getAllFeatures() { + return newFeatureService.findAllFeatures(); + } +} \ No newline at end of file diff --git a/spring-backend/src/main/java/com/example/model/NewFeature.java b/spring-backend/src/main/java/com/example/model/NewFeature.java new file mode 100644 index 000000000..6fa965efc --- /dev/null +++ b/spring-backend/src/main/java/com/example/model/NewFeature.java @@ -0,0 +1,41 @@ +java +package com.example.model; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Entity +public class NewFeature { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String name; + + // Constructors, getters, and setters + + public NewFeature() { + } + + public NewFeature(String name) { + this.name = name; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} \ No newline at end of file diff --git a/spring-backend/src/main/java/com/example/repository/NewFeatureRepository.java b/spring-backend/src/main/java/com/example/repository/NewFeatureRepository.java new file mode 100644 index 000000000..fe3635129 --- /dev/null +++ b/spring-backend/src/main/java/com/example/repository/NewFeatureRepository.java @@ -0,0 +1,10 @@ +java +package com.example.repository; + +import com.example.model.NewFeature; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface NewFeatureRepository extends JpaRepository { +} \ No newline at end of file diff --git a/spring-backend/src/main/java/com/example/service/NewFeatureService.java b/spring-backend/src/main/java/com/example/service/NewFeatureService.java new file mode 100644 index 000000000..75fe61157 --- /dev/null +++ b/spring-backend/src/main/java/com/example/service/NewFeatureService.java @@ -0,0 +1,20 @@ +java +package com.example.service; + +import com.example.model.NewFeature; +import com.example.repository.NewFeatureRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class NewFeatureService { + + @Autowired + private NewFeatureRepository newFeatureRepository; + + public List findAllFeatures() { + return newFeatureRepository.findAll(); + } +} \ No newline at end of file