Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/ai-code-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: "Code Review by Gemini AI"

on:
pull_request:

jobs:
review:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v3
- name: "Get diff of the pull request"
id: get_diff
shell: bash
env:
PULL_REQUEST_HEAD_REF: "${{ github.event.pull_request.head.ref }}"
PULL_REQUEST_BASE_REF: "${{ github.event.pull_request.base.ref }}"
run: |-
git fetch origin "${{ env.PULL_REQUEST_HEAD_REF }}"
git fetch origin "${{ env.PULL_REQUEST_BASE_REF }}"
git checkout "${{ env.PULL_REQUEST_HEAD_REF }}"
git diff "origin/${{ env.PULL_REQUEST_BASE_REF }}" > "diff.txt"
{
echo "pull_request_diff<<EOF";
cat "diff.txt";
echo 'EOF';
} >> $GITHUB_OUTPUT
- uses: ./
name: "Code Review by Gemini AI"
id: review
with:
gemini_api_key: ${{ secrets.GEMINI_API_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
github_repository: ${{ github.repository }}
github_pull_request_number: ${{ github.event.pull_request.number }}
git_commit_hash: ${{ github.event.pull_request.head.sha }}
model: "gemini-1.5-pro"
pull_request_diff: |-
${{ steps.get_diff.outputs.pull_request_diff }}
pull_request_chunk_size: "3500"
extra_prompt: |-
Sempre responda em português brasileiro!
log_level: "DEBUG"
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@
*/
package com.google.cloud.spark.bigquery.acceptance;

import com.google.cloud.ServiceOptions;
import com.google.common.base.Preconditions;
import java.util.Optional;

public class AcceptanceTestConstants {

public static final String REGION = "us-west1";
public static final String DATAPROC_ENDPOINT = REGION + "-dataproc.googleapis.com:443";
public static final String PROJECT_ID =
Preconditions.checkNotNull(
System.getenv("GOOGLE_CLOUD_PROJECT"),
"Please set the 'GOOGLE_CLOUD_PROJECT' environment variable");
Optional.ofNullable(System.getenv("GOOGLE_CLOUD_PROJECT"))
.orElse(ServiceOptions.getDefaultProjectId());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider throwing a NullPointerException with a descriptive message if the project ID cannot be resolved from the environment variable or ADC.

Suggested change
Optional.ofNullable(System.getenv("GOOGLE_CLOUD_PROJECT"))
.orElse(ServiceOptions.getDefaultProjectId());
PROJECT_ID = Optional.ofNullable(System.getenv("GOOGLE_CLOUD_PROJECT"))
.orElseGet(() -> {
String projectId = ServiceOptions.getDefaultProjectId();
if (projectId == null) {
throw new NullPointerException("PROJECT_ID could not be determined. Please set the 'GOOGLE_CLOUD_PROJECT' environment variable or ensure Application Default Credentials are configured.");
}
return projectId;
});

public static final String SERVERLESS_NETWORK_URI =
Preconditions.checkNotNull(
System.getenv("SERVERLESS_NETWORK_URI"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import static org.apache.spark.sql.types.DataTypes.StringType;
import static org.apache.spark.sql.types.DataTypes.TimestampType;

import com.google.cloud.ServiceOptions;
import com.google.cloud.spark.bigquery.integration.model.ColumnOrderTestClass;
import com.google.cloud.spark.bigquery.integration.model.NumStruct;
import com.google.cloud.spark.bigquery.integration.model.StringStruct;
Expand All @@ -43,6 +44,7 @@
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.TimeZone;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -73,9 +75,8 @@ public class TestConstants {
"bigquery-public-data.wikipedia.pageviews_2021";
static final long SHAKESPEARE_TABLE_NUM_ROWS = 164656L;
static final String PROJECT_ID =
Preconditions.checkNotNull(
System.getenv("GOOGLE_CLOUD_PROJECT"),
"Please set the GOOGLE_CLOUD_PROJECT env variable");
Optional.ofNullable(System.getenv("GOOGLE_CLOUD_PROJECT"))
.orElse(ServiceOptions.getDefaultProjectId());
static final String TEMPORARY_GCS_BUCKET_ENV_VARIABLE = "TEMPORARY_GCS_BUCKET";
static final String BIGLAKE_CONNECTION_ID_ENV_VARIABLE = "BIGLAKE_CONNECTION_ID";
static final String TEMPORARY_GCS_BUCKET =
Expand Down
Loading