File tree Expand file tree Collapse file tree 6 files changed +76
-52
lines changed Expand file tree Collapse file tree 6 files changed +76
-52
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ WORKDIR /app
44
55COPY . .
66
7- RUN yarn install && yarn build
7+ RUN yarn install && yarn test && yarn build
88
99RUN rm -rf /build
1010
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ export class FirehoseSubscription extends FirehoseSubscriptionBase {
1717 // use only for debug purposes
1818 for ( const post of ops . posts . creates ) {
1919 console . log ( "================== [NEW POST] ==================" )
20+ console . log ( post . author )
2021 console . log ( post . record . text )
2122 console . log ( "================== [END POST] ==================" )
2223 }
@@ -26,7 +27,7 @@ export class FirehoseSubscription extends FirehoseSubscriptionBase {
2627 const postsToCreate = ops . posts . creates
2728 . filter ( ( create ) => {
2829 // only scala related posts
29- return isAboutScala ( create . record . text ) ;
30+ return isAboutScala ( create . author , create . record . text ) ;
3031 } )
3132 . map ( ( create ) => {
3233 // map scala related posts to a db row
Original file line number Diff line number Diff line change 1+ export const scalaRelatedOrganizationProfiles = [
2+ "did:plc:mb6e2ashxeswusv7f7hwusp5" , // scala-lang.org https://bsky.social/xrpc/com.atproto.identity.resolveHandle?handle=scala-lang.org
3+ "did:plc:5nlshbn5adh3fjwzyz7xjpwl" , // Scala Space https://bsky.social/xrpc/com.atproto.identity.resolveHandle?handle=scalaspace.bsky.social
4+ "did:plc:xs35x5l4ogj3g4eymh6ngcsr" , // Scala Times https://bsky.social/xrpc/com.atproto.identity.resolveHandle?handle=scalatimes.com
5+ ]
Original file line number Diff line number Diff line change 1+ const scalalang = [
2+ "scala" , "scala3" , "dotty"
3+ ]
4+
5+ const typelevel = [
6+ "cats-effect"
7+ ]
8+
9+ const scalameta = [
10+ "munit" , "scalameta" , "scalafmt" ,
11+ // "mdoc"
12+ ]
13+
14+ const softwaremill = [
15+ "scalar" , "scalarconf"
16+ ]
17+
18+ const sbt = [
19+ "sbt"
20+ ]
21+
22+ const lihaoi = [
23+ "os-lib" , "requests-scala"
24+ ]
25+
26+ const lightbend = [
27+ "akka" , "playframework"
28+ ]
29+
30+ const others = [
31+ "pekko"
32+ ]
33+
34+ function hashTag ( word : String ) {
35+ return `#${ word } `
36+ }
37+
38+ export const allHashTags =
39+ scalalang . concat ( typelevel ,
40+ scalameta ,
41+ softwaremill ,
42+ // sbt, // sbt seems to be a thing in TV in Brasil
43+ // lihaoi, // apparently people like to discuss hardware mills a lot
44+ lightbend ,
45+ others
46+ ) . map ( w => hashTag ( w ) )
Original file line number Diff line number Diff line change 1- const scalalang = [
2- "scala" , "scala3" , "dotty"
3- ]
1+ import { allHashTags } from "./hashtags" ;
2+ import { scalaRelatedOrganizationProfiles } from "./accounts" ;
43
5- const typelevel = [
6- "cats-effect"
7- ]
8-
9- const scalameta = [
10- "munit" , "scalameta" , "scalafmt" ,
11- // "mdoc"
12- ]
13-
14- const softwaremill = [
15- "scalar" , "scalarconf"
16- ]
17-
18- const sbt = [
19- "sbt"
20- ]
21-
22- const lihaoi = [
23- "os-lib" , "requests-scala"
24- ]
25-
26- const lightbend = [
27- "akka" , "playframework"
28- ]
29-
30- const others = [
31- "pekko"
32- ]
33-
34- const allHashTags =
35- scalalang . concat ( typelevel ,
36- scalameta ,
37- softwaremill ,
38- // sbt, // sbt seems to be a thing in TV in Brasil
39- // lihaoi, // apparently people like to discuss hardware mills a lot
40- lightbend ,
41- others
42- ) . map ( w => hashTag ( w ) )
43-
44- function hashTag ( word : String ) {
45- return `#${ word } `
46- }
47-
48- export function isAboutScala ( text : string ) : boolean {
4+ function containsRelevantHashtag ( text : string ) : boolean {
495 const input = text . toLowerCase ( ) ;
506 const textWords = input . split ( / \s + / ) ;
517 return allHashTags . map ( v => v . toLowerCase ( ) ) . some ( tag => textWords . includes ( tag ) ) ;
528}
539
10+ function postedByScalaOrgAccount ( author : string ) : boolean {
11+ return scalaRelatedOrganizationProfiles . includes ( author ) ;
12+ }
13+
14+ export function isAboutScala ( author : string , text : string ) : boolean {
15+ return postedByScalaOrgAccount ( author ) || containsRelevantHashtag ( text ) ;
16+ }
17+
Original file line number Diff line number Diff line change 1+ import { scalaRelatedOrganizationProfiles } from '../../src/scala/accounts' ;
12import { isAboutScala } from '../../src/scala/index' ;
23
4+ const randomAuthorDid = "did:plc:abcde12345"
5+
36describe ( 'testing isAboutScala' , ( ) => {
47 test ( 'the #Scala hashtag should be picked up' , ( ) => {
58 expect (
6- isAboutScala ( "#Scala" )
9+ isAboutScala ( randomAuthorDid , "#Scala" )
710 ) . toBe ( true ) ;
811 } ) ;
912 test ( 'proper message should be qualified as Scala related' , ( ) => {
1013 expect (
11- isAboutScala ( "We've a full house at the #London #Scala OSS Hack night this Wednesday! www.meetup.com/london-scala..." )
14+ isAboutScala ( randomAuthorDid , "We've a full house at the #London #Scala OSS Hack night this Wednesday! www.meetup.com/london-scala..." )
15+ ) . toBe ( true ) ;
16+ } ) ;
17+ test ( 'post by scala related org account should be qualified as Scala related' , ( ) => {
18+ expect (
19+ isAboutScala ( scalaRelatedOrganizationProfiles [ 0 ] , "This one doesn't have a hashtag" )
1220 ) . toBe ( true ) ;
1321 } ) ;
1422 test ( 'empty message should not be qualified as Scala' , ( ) => {
1523 expect (
16- isAboutScala ( "" )
24+ isAboutScala ( randomAuthorDid , "" )
1725 ) . toBe ( false ) ;
1826 } ) ;
1927} ) ;
You can’t perform that action at this time.
0 commit comments