Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into allowlist-feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Corantin committed Oct 10, 2024
2 parents 763de7d + ffed359 commit fc2d52e
Show file tree
Hide file tree
Showing 44 changed files with 12,671 additions and 12,891 deletions.
101 changes: 75 additions & 26 deletions .github/workflows/ai-code-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
permissions:
contents: read
pull-requests: write
issues: read
steps:
- uses: actions/checkout@v3

Expand All @@ -24,8 +25,8 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_ID: ${{ github.event.comment.node_id }}

- name: Fetch PR details using GitHub API
id: pr-details
- name: Fetch filtered PR diff (only .ts, .tsx, .sol files)
id: pr-diff
uses: actions/github-script@v6
with:
script: |
Expand All @@ -35,40 +36,88 @@ jobs:
repo: context.repo.repo,
pull_number: pr_number
});
return pr.data;
const { data: diff } = await github.request('GET /repos/{owner}/{repo}/pulls/{pull_number}', {
headers: {
accept: 'application/vnd.github.v3.diff'
},
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr_number
});
- name: "Get diff of the pull request"
id: get_diff
shell: bash
env:
PULL_REQUEST_HEAD_REF: "${{ steps.pr-details.outputs.head.ref }}"
PULL_REQUEST_BASE_REF: "${{ steps.pr-details.outputs.base.ref }}"
run: |-
echo "PULL_REQUEST_HEAD_REF: $PULL_REQUEST_HEAD_REF"
echo "PULL_REQUEST_BASE_REF: $PULL_REQUEST_BASE_REF"
# Only include changes to .ts, .tsx, and .sol files in the diff
git diff "origin/${{ env.PULL_REQUEST_BASE_REF }}" -- '*.ts' '*.tsx' '*.sol' > "diff.txt"
{
echo "pull_request_diff<<EOF";
cat "diff.txt";
echo 'EOF';
} >> $GITHUB_OUTPUT # save the filtered diff to an output variable
// Initialize variables to store filtered diff and a flag for capturing lines
let filteredDiff = '';
let capture = false;
// Iterate over each line in the diff
diff.split('\n').forEach(line => {
// Check if the line is a diff line for the relevant file types
if (line.startsWith('diff --git')) {
capture = line.endsWith('.ts') || line.endsWith('.tsx') || line.endsWith('.sol');
}
// If capturing, append the current line to the filtered diff
if (capture) {
filteredDiff += line + '\n';
}
});
// Get the head commit SHA
const headSha = pr.data.head.sha;
// Set outputs for the filtered diff and head SHA
core.setOutput("diff", filteredDiff);
core.setOutput("headSha", headSha);
- name: Log filtered diff to file
id: log-diff
continue-on-error: true
run: |
echo "${{ steps.pr-diff.outputs.diff }}"
- uses: rubensflinco/[email protected]
name: "Code Review by Gemini AI"
continue-on-error: true
id: review
with:
gemini_api_key: ${{ secrets.GEMINI_API_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
github_repository: ${{ github.repository }}
github_pull_request_number: ${{ steps.pr-details.outputs.number }}
git_commit_hash: ${{ steps.pr-details.outputs.head.sha }}
github_pull_request_number: ${{ github.event.issue.number }}
git_commit_hash: ${{ steps.pr-diff.outputs.headSha }}
model: "gemini-1.5-pro-latest"
pull_request_diff: |-
${{ steps.get_diff.outputs.pull_request_diff }}
pull_request_chunk_size: "3500"
${{ steps.pr-diff.outputs.diff }}
pull_request_chunk_size: "5000"
extra_prompt: |-
Only review files with extensions: .ts, .tsx, .sol
Focus your review on code logic, security vulnerabilities, and potential improvements in these files.
Make a pull request review in regards of the added and removed code.
Start with a summary of the changes and then list detail the review and suggestions.
Focus on code quality, security, performance, best practices and potential mistakes.
Never ask to provide more code and only review the code you received even if its partial.
When a line start with a minus (`-`) it means that the line was removed, when it starts with plus (`+`) it means that the line was added.
log_level: "DEBUG"

- name: Add thumbs down reaction if something went wrong
if: steps.review.outcome == 'failure'
run: gh api graphql --silent --raw-field query="mutation AddReaction {addReaction(input:{subjectId:\"$NODE_ID\",content:THUMBS_DOWN}){reaction{content}subject{id}}}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_ID: ${{ github.event.comment.node_id }}

- name: Get Gemini step log
if: steps.review.outcome == 'failure'
id: get-gemini-log
run: |
echo "gemini_log<<EOF" >> $GITHUB_OUTPUT
gh run view ${{ steps.review.outputs.run_id }} --log >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Add comment with log
if: steps.review.outcome == 'failure'
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Gemini Code Review encountered an error. Here is the step log:\n\n```\n${{ steps.get-gemini-log.outputs.gemini_log }}\n```'
});
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ cache/
pkg/subgraph/generated
pkg/**/data
cookies.json
.graphclientrc.yml

lcov.info
# some abi should be ignored
Expand Down
2 changes: 1 addition & 1 deletion apps/web/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ module.exports = {
"no-unused-expressions": "error",
"no-unsafe-optional-chaining": "error",
"import/extensions": "off",
"@typescript-eslint/quotes": ["error", "double"],
"@typescript-eslint/quotes": ["error", "double", { avoidEscape: true }],
"@typescript-eslint/no-use-before-define": "off",
"jsx-a11y/no-static-element-interactions": "off",
"react/no-array-index-key": "warn",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { ConvictionBarChart } from "@/components/Charts/ConvictionBarChart";
import { DisputeButton } from "@/components/DisputeButton";
import { LoadingSpinner } from "@/components/LoadingSpinner";
import MarkdownWrapper from "@/components/MarkdownWrapper";
import { Skeleton } from "@/components/Skeleton";
import { usePubSubContext } from "@/contexts/pubsub.context";
import { useChainIdFromPath } from "@/hooks/useChainIdFromPath";
import { useContractWriteWithConfirmations } from "@/hooks/useContractWriteWithConfirmations";
Expand Down Expand Up @@ -68,11 +69,6 @@ export default function Page({

const { publish } = usePubSubContext();
const chainId = useChainIdFromPath();
const { data: poolToken } = useToken({
address: poolTokenAddr,
enabled: !!poolTokenAddr,
chainId,
});
const { data: ipfsResult } = useMetadataIpfsFetch({
hash: proposalData?.metadataHash,
enabled: !proposalData?.metadata,
Expand All @@ -81,24 +77,33 @@ export default function Page({
const isProposerConnected =
proposalData?.submitter === address?.toLowerCase();

const proposalType = proposalData?.strategy.config?.proposalType;
const isSignalingType = PoolTypes[proposalType] === "signaling";
const requestedAmount = proposalData?.requestedAmount;
const beneficiary = proposalData?.beneficiary as Address | undefined;
const submitter = proposalData?.submitter as Address | undefined;
const proposalStatus = ProposalStatus[proposalData?.proposalStatus];

const { data: poolToken } = useToken({
address: poolTokenAddr,
enabled: !!poolTokenAddr && !isSignalingType,
chainId,
});

const {
currentConvictionPct,
thresholdPct,
totalSupportPct,
updatedConviction,
timeToPass,
triggerConvictionRefetch,
} = useConvictionRead({
proposalData,
tokenData: data?.tokenGarden,
strategyConfig: proposalData?.strategy?.config,
tokenData: data?.tokenGarden?.decimals,
enabled: proposalData?.proposalNumber != null,
});

const proposalType = proposalData?.strategy.config?.proposalType;
const requestedAmount = proposalData?.requestedAmount;
const beneficiary = proposalData?.beneficiary as Address | undefined;
const submitter = proposalData?.submitter as Address | undefined;
const isSignalingType = PoolTypes[proposalType] === "signaling";
const proposalStatus = ProposalStatus[proposalData?.proposalStatus];

//encode proposal id to pass as argument to distribute function
const encodedDataProposalId = (proposalId_: bigint) => {
const encodedProposalId = encodeAbiParameters(
Expand Down Expand Up @@ -166,9 +171,11 @@ export default function Page({
<div className="flex w-full flex-col gap-8">
<div>
<div className="mb-4 flex flex-col items-start gap-4 sm:mb-2 sm:flex-row sm:items-center sm:justify-between sm:gap-2">
<h2>
{metadata?.title} #{proposalIdNumber.toString()}
</h2>
<Skeleton isLoading={!metadata} className="!w-96 h-8">
<h2>
{metadata?.title} #{proposalIdNumber.toString()}
</h2>
</Skeleton>
<Badge type={proposalType} />
</div>
<div className="flex items-center justify-between gap-4 sm:justify-start">
Expand All @@ -181,15 +188,19 @@ export default function Page({
</p>
</div>
</div>
<MarkdownWrapper>
{metadata?.description ?? "No description found"}
</MarkdownWrapper>
<div>
<Skeleton rows={5} isLoading={!metadata}>
<MarkdownWrapper>
{metadata?.description ?? "No description found"}
</MarkdownWrapper>
</Skeleton>
</div>
<div className="flex justify-between flex-wrap gap-2">
<div className="flex flex-col gap-2">
{!isSignalingType && (
<>
<Statistic
label={"requested amount"}
label={"request amount"}
icon={<InformationCircleIcon />}
>
<DisplayNumber
Expand Down Expand Up @@ -264,7 +275,9 @@ export default function Page({
thresholdPct={thresholdPct}
proposalSupportPct={totalSupportPct}
isSignalingType={isSignalingType}
proposalId={Number(proposalIdNumber)}
proposalNumber={Number(proposalIdNumber)}
timeToPass={Number(timeToPass)}
onReadyToExecute={triggerConvictionRefetch}
/>
</>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ export default function Page({

const strategyObj = data?.cvstrategies?.[0];
const poolTokenAddr = strategyObj?.token as Address;
const proposalType = strategyObj?.config.proposalType;
const { data: poolToken } = useToken({
address: poolTokenAddr,
enabled: !!poolTokenAddr,
enabled: !!poolTokenAddr && PoolTypes[proposalType] === "funding",
chainId: +chain,
});

Expand Down Expand Up @@ -93,7 +94,10 @@ export default function Page({

const tokenGarden = data?.tokenGarden;

if (!tokenGarden || !poolToken) {
if (
!tokenGarden ||
(!poolToken && PoolTypes[proposalType] === "funding")
) {
return (
<div className="mt-96">
<LoadingSpinner />
Expand All @@ -108,7 +112,6 @@ export default function Page({
const pointSystem = data.cvstrategies?.[0].config.pointSystem;
const communityAddress = strategyObj.registryCommunity.id as Address;
const alloInfo = data.allos[0];
const proposalType = strategyObj.config.proposalType;
const poolAmount = strategyObj.poolAmount as number;
const spendingLimitPct =
(Number(strategyObj.config.maxRatio || 0) / CV_SCALE_PRECISION) * 100;
Expand All @@ -132,7 +135,7 @@ export default function Page({
/>
{isEnabled && (
<>
{PoolTypes[proposalType] !== "signaling" && (
{poolToken && PoolTypes[proposalType] !== "signaling" && (
<PoolMetrics
poolToken={poolToken}
alloInfo={alloInfo}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
} from "@/components";
import { LoadingSpinner } from "@/components/LoadingSpinner";
import MarkdownWrapper from "@/components/MarkdownWrapper";
import { Skeleton } from "@/components/Skeleton";
import { TokenGardenFaucet } from "@/components/TokenGardenFaucet";
import { isProd } from "@/configs/isProd";
import { QUERY_PARAMS } from "@/constants/query-params";
Expand Down Expand Up @@ -359,9 +360,9 @@ export default function Page({
<section ref={covenantSectionRef} className="section-layout">
<h2 className="mb-4">Covenant</h2>
{registryCommunity?.covenantIpfsHash ?
covenant ?
<MarkdownWrapper>{covenant}</MarkdownWrapper>
: <LoadingSpinner />
<Skeleton isLoading={!covenant} rows={5}>
<MarkdownWrapper>{covenant!}</MarkdownWrapper>
</Skeleton>
: <p className="italic">No covenant was submitted.</p>}
<div className="mt-10 flex justify-center">
<Image
Expand Down
Loading

0 comments on commit fc2d52e

Please sign in to comment.