Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions components/grant-application/steps/ProjectDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default function ProjectDetails({ register, watch, errors }: StepProps) {
<option value="">(Choose One)</option>
<option value="core">Bitcoin Core</option>
<option value="education">Education</option>
<option value="security">Security</option>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit, this list appears to be in alphabetical order. If that was the intent, the new entry breaks that.

<option value="layer1">Layer1 / Bitcoin</option>
<option value="layer2">Layer2 / Lightning</option>
<option value="ecash">Layer3 / eCash</option>
Expand Down
51 changes: 9 additions & 42 deletions pages/api/github.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { NextApiRequest, NextApiResponse } from 'next/types'
import {
getApplicationIssueLabels,
getApplicationRepo,
normalizeMainFocus,
} from '../../utils/application-routing'

const GH_ACCESS_TOKEN = process.env.GH_ACCESS_TOKEN
const GH_ORG = process.env.GH_ORG
Expand Down Expand Up @@ -134,48 +139,10 @@ ${req.body.video_application ? req.body.video_application : 'None provided.'}
${req.body.anything_else ? req.body.anything_else : 'No.'}
${contactFooter}`

// Label set according to "main focus" (absent for RED applications)
const mainFocus = req.body.main_focus
? `${req.body.main_focus}`.toLowerCase()
: ''
const issueLabels = mainFocus ? [mainFocus] : []
if (mainFocus === 'layer1' || mainFocus === 'layer2') {
issueLabels.push('bitcoin') // L1 & L2 = subset of Bitcoin
}

// Add label for applications from common grant app
if (req.body.source === 'common-grant-app') {
issueLabels.push('common-grant-app')
}

// Repo set according to "main focus"
let appRepo = GH_APP_REPO
if (mainFocus === 'nostr') {
appRepo = `${GH_APP_REPO}-nostr`
}
if (mainFocus === 'layer1') {
appRepo = `${GH_APP_REPO}-layer1`
}
if (mainFocus === 'layer2') {
appRepo = `${GH_APP_REPO}-layer2`
}
if (mainFocus === 'core') {
appRepo = `${GH_APP_REPO}-core`
}
if (mainFocus === 'ecash') {
appRepo = `${GH_APP_REPO}-ecash`
}

// Tag depending on request for grant and/or request for listing
req.body.LTS && issueLabels.push('LTS')
req.body.RED && issueLabels.push('RED')

// Additional tags based on yes/no answers
req.body.has_received_funding === 'yes' && issueLabels.push('prior funding')
if (!req.body.RED) {
!req.body.free_open_source && issueLabels.push('not FLOSS')
!req.body.are_you_lead && issueLabels.push('surrogate')
}
// Labels and repo are set according to main focus.
const mainFocus = normalizeMainFocus(req.body.main_focus)
const issueLabels = getApplicationIssueLabels(req.body)
const appRepo = getApplicationRepo(GH_APP_REPO, mainFocus)

try {
await octokit.rest.issues.create({
Expand Down
2 changes: 1 addition & 1 deletion public/static/opensats-grant-application-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ application at https://opensats.org/apply/grant

**Project Name:**

**Main Focus:** (Bitcoin, Nostr, Layer 1, Layer 2, Core, Ecash, Education, Other)
**Main Focus:** (Bitcoin, Nostr, Layer 1, Layer 2, Core, Ecash, Education, Security, Other)

### Project Description

Expand Down
38 changes: 38 additions & 0 deletions utils/application-routing.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/** @jest-environment node */
/* eslint-env jest, node */

const {
getApplicationIssueLabels,
getApplicationRepo,
normalizeMainFocus,
} = require('./application-routing.ts')

describe('application routing', () => {
it('normalizes main focus values', () => {
expect(normalizeMainFocus('Security')).toBe('security')
expect(normalizeMainFocus(undefined)).toBe('')
})

it('labels regular security grant applications', () => {
expect(
getApplicationIssueLabels({
main_focus: 'security',
free_open_source: true,
are_you_lead: true,
})
).toEqual(['security'])
})

it('keeps security applications in the default applications repo', () => {
expect(getApplicationRepo('applications', 'security')).toBe('applications')
})

it('routes known focus-specific applications to their repos', () => {
expect(getApplicationRepo('applications', 'layer1')).toBe(
'applications-layer1'
)
expect(getApplicationIssueLabels({ main_focus: 'layer2' })).toContain(
'bitcoin'
)
})
})
41 changes: 41 additions & 0 deletions utils/application-routing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const REPO_SUFFIX_BY_MAIN_FOCUS: Record<string, string> = {
core: '-core',
ecash: '-ecash',
layer1: '-layer1',
layer2: '-layer2',
nostr: '-nostr',
}

export function normalizeMainFocus(mainFocus: unknown) {
return mainFocus ? `${mainFocus}`.toLowerCase() : ''
}

export function getApplicationRepo(baseRepo: string, mainFocus: unknown) {
return `${baseRepo}${
REPO_SUFFIX_BY_MAIN_FOCUS[normalizeMainFocus(mainFocus)] || ''
}`
}

export function getApplicationIssueLabels(body: Record<string, unknown>) {
const mainFocus = normalizeMainFocus(body.main_focus)
const issueLabels = mainFocus ? [mainFocus] : []

if (mainFocus === 'layer1' || mainFocus === 'layer2') {
issueLabels.push('bitcoin')
}

if (body.source === 'common-grant-app') {
issueLabels.push('common-grant-app')
}

if (body.LTS) issueLabels.push('LTS')
if (body.RED) issueLabels.push('RED')
if (body.has_received_funding === 'yes') issueLabels.push('prior funding')

if (!body.RED) {
if (!body.free_open_source) issueLabels.push('not FLOSS')
if (!body.are_you_lead) issueLabels.push('surrogate')
}

return issueLabels
}
Loading