Skip to content

Commit

Permalink
Merge branch 'master' into custom_domain
Browse files Browse the repository at this point in the history
  • Loading branch information
Soxasora authored Mar 9, 2025
2 parents 2acbb44 + 5b7ff24 commit fa3b9a2
Show file tree
Hide file tree
Showing 20 changed files with 269 additions and 76 deletions.
27 changes: 17 additions & 10 deletions .github/workflows/extend-awards.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
name: extend-awards
run-name: Extending awards
on:
pull_request:
pull_request_target:
types: [ closed ]
branches:
- master
permissions:
pull-requests: write
contents: write
issues: read
jobs:
unfiltered:
runs-on: ubuntu-latest
steps:
- run: echo '${{ toJson(github) }}'
if_merged:
if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true
if: |
github.event_name == 'pull_request_target' &&
github.event.action == 'closed' &&
github.event.pull_request.merged == true &&
github.event.pull_request.head.ref != 'extend-awards/patch'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.13'
- run: pip install requests
- run: python extend-awards.py '${{ toJson(github) }}'
- run: python extend-awards.py
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_CONTEXT: ${{ toJson(github) }}
- uses: peter-evans/create-pull-request@v7
with:
commit-message: extending awards
title: Extending awards
add-paths: awards.csv
branch: extend-awards/patch
commit-message: Extending awards.csv
title: Extending awards.csv
body: A PR was merged that solves an issue and awards.csv should be extended.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ docker/lnbits/data
!docker/lndk/tls-*.pem

# nostr link extract
scripts/nostr-link-extract.config.json
scripts/nostr-link-extract.config.json
scripts/nostr-links.db
3 changes: 1 addition & 2 deletions api/paidAction/receive.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ export const anonable = false

export const paymentMethods = [
PAID_ACTION_PAYMENT_METHODS.P2P,
PAID_ACTION_PAYMENT_METHODS.DIRECT,
PAID_ACTION_PAYMENT_METHODS.OPTIMISTIC
PAID_ACTION_PAYMENT_METHODS.DIRECT
]

export async function getCost ({ msats }) {
Expand Down
4 changes: 3 additions & 1 deletion api/resolvers/admin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { SN_ADMIN_IDS } from '@/lib/constants'

export default {
Query: {
snl: async (parent, _, { models }) => {
Expand All @@ -7,7 +9,7 @@ export default {
},
Mutation: {
onAirToggle: async (parent, _, { models, me }) => {
if (me.id !== 616) {
if (!me || !SN_ADMIN_IDS.includes(me.id)) {
throw new Error('not an admin')
}
const { id, live } = await models.snl.findFirst()
Expand Down
15 changes: 13 additions & 2 deletions awards.csv
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,17 @@ SatsAllDay,issue,#1820,#1819,easy,,,1,9k,[email protected],2025-01-27
Soxasora,pr,#1814,#1736,easy,,,,100k,[email protected],2025-01-27
jason-me,pr,#1857,,easy,,,,100k,[email protected],2025-02-08
ed-kung,pr,#1901,#323,good-first-issue,,,,20k,[email protected],2025-02-14
Scroogey-SN,pr,#1911,#1905,good-first-issue,,,1,18k,???,???
Scroogey-SN,pr,#1928,#1924,good-first-issue,,,,20k,???,???
Scroogey-SN,pr,#1911,#1905,good-first-issue,,,1,18k,[email protected],???
Scroogey-SN,pr,#1928,#1924,good-first-issue,,,,20k,[email protected],???
dtonon,issue,#1928,#1924,good-first-issue,,,,2k,???,???
ed-kung,pr,#1926,#1914,medium-hard,,,,500k,[email protected],???
ed-kung,issue,#1926,#1914,medium-hard,,,,50k,[email protected],???
ed-kung,pr,#1926,#1927,easy,,,,100k,[email protected],???
ed-kung,issue,#1926,#1927,easy,,,,10k,[email protected],???
ed-kung,issue,#1913,#1890,good-first-issue,,,,2k,[email protected],???
Scroogey-SN,pr,#1930,#1167,good-first-issue,,,,20k,[email protected],???
itsrealfake,issue,#1930,#1167,good-first-issue,,,,2k,[email protected],???
Scroogey-SN,pr,#1948,#1849,medium,urgent,,,750k,[email protected],???
felipebueno,issue,#1947,#1945,good-first-issue,,,,2k,[email protected],???
ed-kung,pr,#1952,#1951,easy,,,,100k,[email protected],???
ed-kung,issue,#1952,#1951,easy,,,,10k,[email protected],???
3 changes: 2 additions & 1 deletion components/link-to-context.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
.linkBoxParent input,
.linkBoxParent iframe,
.linkBoxParent video,
.linkBoxParent pre,
.linkBoxParent img {
pointer-events: auto !important;
}
}
5 changes: 4 additions & 1 deletion components/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,10 @@ export function NotificationAlert () {
error
? (
<Alert variant='danger' dismissible onClose={() => setError(null)}>
<span>{error.toString()}</span>
<span>{navigator?.brave && error.name === 'AbortError'
? 'Push registration failed. Enable "Use Google services for push messaging" in Brave\'s privacy settings and try again.'
: error.toString()}
</span>
</Alert>
)
: showAlert
Expand Down
9 changes: 6 additions & 3 deletions components/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@ export function SearchText ({ text }) {

// this is one of the slowest components to render
export default memo(function Text ({ rel = UNKNOWN_LINK_REL, imgproxyUrls, children, tab, itemId, outlawed, topLevel }) {
// would the text overflow on the current screen size?
const [overflowing, setOverflowing] = useState(false)
const router = useRouter()
// should we show the full text?
const [show, setShow] = useState(false)
const containerRef = useRef(null)

const router = useRouter()
const [mathJaxPlugin, setMathJaxPlugin] = useState(null)

// we only need mathjax if there's math content between $$ tags
Expand All @@ -69,9 +72,9 @@ export default memo(function Text ({ rel = UNKNOWN_LINK_REL, imgproxyUrls, child

// if we are navigating to a hash, show the full text
useEffect(() => {
setShow(router.asPath.includes('#') && !router.asPath.includes('#itemfn-'))
setShow(router.asPath.includes('#'))
const handleRouteChange = (url, { shallow }) => {
setShow(url.includes('#') && !url.includes('#itemfn-'))
setShow(url.includes('#'))
}

router.events.on('hashChangeStart', handleRouteChange)
Expand Down
9 changes: 5 additions & 4 deletions components/text.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,16 @@
.p:has(> .mediaContainer) .mediaContainer img,
.p:has(> .mediaContainer) .mediaContainer video
{
block-size: revert-layer;
min-width: 30%;
max-width: stretch;
}

.p.onlyImages {
display: block;
.p:has(> .mediaContainer) .mediaContainer img
{
block-size: revert-layer;
}

.p.onlyImages:has(> .mediaContainer.loaded) {
.p.onlyImages {
display: flex;
flex-direction: row;
flex-wrap: wrap;
Expand Down
54 changes: 54 additions & 0 deletions docs/dev/extend-awards.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Automatically extend awards.csv

## Overview

Whenever a pull request (PR) is merged in the [stacker.news](https://github.com/stackernews/stacker.news) repository, a [GitHub Action](https://docs.github.com/en/actions) is triggered:

If the merged PR solves an issue with [award tags](https://github.com/stackernews/stacker.news?tab=readme-ov-file#contributing),
the amounts due to the PR and issue authors are calculated and corresponding lines are added to the [awards.csv](https://github.com/stackernews/stacker.news/blob/master/awards.csv) file,
and a PR is opened for this change.

## Action

The action is defined in [.github/workflows/extend-awards.yml](.github/workflows/extend-awards.yml).

Filters on the event type and parameters ensure the action is [triggered only on merged PRs](https://stackoverflow.com/questions/60710209/trigger-github-actions-only-when-pr-is-merged).

The primary job consists of several steps:
- [checkout](https://github.com/actions/checkout) checks out the repository
- [setup-python](https://github.com/actions/setup-python) installs [Python](https://en.wikipedia.org/wiki/Python_(programming_language))
- [pip](https://en.wikipedia.org/wiki/Pip_%28package_manager%29) installs the [requests](https://docs.python-requests.org/en/latest/index.html) module
- a script (see below) is executed, which appends lines to [awards.csv](awards.csv) if needed
- [create-pull-request](https://github.com/peter-evans/create-pull-request) looks for modified files and creates (or updates) a PR

## Script

The script is [extend-awards.py](extend-awards.py).

The script extracts from the [environment](https://en.wikipedia.org/wiki/Environment_variable) an authentication token needed for the [GitHub REST API](https://docs.github.com/en/rest/about-the-rest-api/about-the-rest-api) and the [context](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs) containing the event details including the merged PR (formatted in [JSON](https://en.wikipedia.org/wiki/JSON)).

In the merged PR's title and body it searches for the first [GitHub issue URL](https://github.com/stackernews/stacker.news/issues/) or any number with a hash symbol (#) prefix, and takes this as the issue being solved by the PR.

Using the GitHub REST API it fetches the issue and analyzes its tags for difficulty and priority.

It fetches the issue's timeline and counts the number of reviews completed with status 'changes requested' to calculate the amount reduction.

It calculates the amounts due to the PR author and the issue author.

It reads the existing awards.csv file to suppress appending redundant lines (same user, PR, and issue) and fill known receive methods (same user).

Finally, it appends zero, one, or two lines to the awards.csv file.

## Diagnostics

In the GitHub web interface under 'Actions' each invokation of the action can be viewed, including environment and [output and errors](https://en.wikipedia.org/wiki/Standard_streams) of the script. First, the specific invokation is selected, then the job 'if_merged', then the step 'Run python extend-awards.py'. The environment is found by expanding the inner 'Run python extended-awards.py' on the first line.

The normal output includes details about the issue number found, the amount calculation, or the reason for not appending lines.

The error output may include a [Python traceback](https://realpython.com/python-traceback/) which helps to explain the error.

The environment contains in GITHUB_CONTEXT the event details, which may be required to understand the error.

## Security considerations

The create-pull-request step requires [workflow permissions](https://github.com/peter-evans/create-pull-request#workflow-permissions).
14 changes: 12 additions & 2 deletions docs/dev/semantic-search.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Getting semantic search setup in OpenSearch is a multistep process.
Getting semantic search setup in OpenSearch is currently a multistep, manual process. To configure semantic search, enter the following commands into OpenSearch's REST API. You can do this in Dev Tools in the OpenSearch Dashboard (after starting your SN dev environment, point your browser to localhost:5601). You can also use CURL to send these commands to localhost:9200.

### step 1: configure the ml plugin
```json
Expand Down Expand Up @@ -67,7 +67,7 @@ PUT /_ingest/pipeline/nlp-ingest-pipeline
},
{
"text_embedding": {
"model_id": "6whlBY0B2sj1ObjeeD5d",
"model_id": "<model id>",
"field_map": {
"text": "text_embedding",
"title": "title_embedding"
Expand Down Expand Up @@ -306,3 +306,13 @@ GET /item-nlp/_search
}
```

### step 12: configure the development environment to use the nlp pipeline

Add the following lines to `.env.local`:

```
OPENSEARCH_INDEX=item-nlp
OPENSEARCH_MODEL_ID=<model id>
```

Note that you won't have to re-do the above steps each time you restart your dev instance. The OpenSearch configuration is saved to a local volume.
22 changes: 5 additions & 17 deletions extend-awards.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import json, os, re, requests, sys
import json, os, re, requests

difficulties = {'good-first-issue':20000,'easy':100000,'medium':250000,'medium-hard':500000,'hard':1000000}
priorities = {'low':0.5,'medium':1.5,'high':2,'urgent':3}
Expand Down Expand Up @@ -56,11 +56,8 @@ def countReviews(pr):
count += 1
return count

def checkPR(pr):
i = getIssue(pr)
if not 'pull_request' in i or not 'merged_at' in i['pull_request']:
print('pr %s is not a merged pull request' % pr)
return
def checkPR(i):
pr = str(i['number'])
print('pr %s' % pr)
n = findIssueInPR(i)
if not n:
Expand Down Expand Up @@ -103,14 +100,5 @@ def checkPR(pr):
s = s.split('\n')[0]
awards.append(s.split(','))

j = json.loads(sys.argv[1])
url = j['event']['pull_request']['_links']['commits']['href']
r = sess.get(url, headers=headers)
j = json.loads(r.text)
for c in j:
m = re.search('\\(#([0-9]+)\\)$', c['commit']['message'].split('\n')[0])
if m:
checkPR(m.group(1))
exit(0)
print('no PR found in commit')

j = json.loads(os.getenv('GITHUB_CONTEXT'))
checkPR(j['event']['pull_request'])
4 changes: 1 addition & 3 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ export const RESERVED_MAX_USER_ID = 615
export const GLOBAL_SEED = USER_ID.k00b
export const FREEBIE_BASE_COST_THRESHOLD = 10

// WIP ultimately subject to this list: https://ofac.treasury.gov/sanctions-programs-and-country-information
// From lawyers: north korea, cuba, iran, ukraine, syria
export const SANCTIONED_COUNTRY_CODES = ['KP', 'CU', 'IR', 'UA', 'SY']
export const SANCTIONED_COUNTRY_CODES = process.env.SANCTIONED_COUNTRY_CODES?.split(',') || []

export const TERRITORY_COST_MONTHLY = 50000
export const TERRITORY_COST_YEARLY = 500000
Expand Down
1 change: 1 addition & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ module.exports = withPlausibleProxy()({
'process.env.NEXT_PUBLIC_NORMAL_POLL_INTERVAL': JSON.stringify(process.env.NEXT_PUBLIC_NORMAL_POLL_INTERVAL),
'process.env.NEXT_PUBLIC_LONG_POLL_INTERVAL': JSON.stringify(process.env.NEXT_PUBLIC_LONG_POLL_INTERVAL),
'process.env.NEXT_PUBLIC_EXTRA_LONG_POLL_INTERVAL': JSON.stringify(process.env.NEXT_PUBLIC_EXTRA_LONG_POLL_INTERVAL),
'process.env.SANCTIONED_COUNTRY_CODES': JSON.stringify(process.env.SANCTIONED_COUNTRY_CODES),
'process.env.NEXT_IS_EXPORT_WORKER': 'true'
})
]
Expand Down
9 changes: 3 additions & 6 deletions pages/api/auth/[...nextauth].js
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,12 @@ function getCallbacks (req, res) {
token.sub = Number(token.id)
}

// this only runs during a signup/login because response is only defined during signup/login
// and will add the multi_auth cookies for the user we just logged in as
if (req && res) {
req = new NodeNextRequest(req)
res = new NodeNextResponse(res)
// add multi_auth cookie for user that just logged in
if (user && req && res) {
const secret = process.env.NEXTAUTH_SECRET
const jwt = await encodeJWT({ token, secret })
const me = await prisma.user.findUnique({ where: { id: token.id } })
setMultiAuthCookies(req, res, { ...me, jwt })
setMultiAuthCookies(new NodeNextRequest(req), new NodeNextResponse(res), { ...me, jwt })
}

return token
Expand Down
2 changes: 1 addition & 1 deletion pages/api/lnurlp/[username]/pay.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ export default async ({ query: { username, amount, nostr, comment, payerdata: pa
})
} catch (error) {
console.log(error)
res.status(400).json({ status: 'ERROR', reason: 'could not generate invoice' })
res.status(400).json({ status: 'ERROR', reason: 'could not generate invoice to customer\'s attached wallet' })
}
}
Loading

0 comments on commit fa3b9a2

Please sign in to comment.