1
1
import { Context , Probot } from "probot" ;
2
- import { getRepoOwnerId , getRepoOwnerLogin } from "./context" ;
2
+ import { getRepoOwnerId , getRepoOwnerLogin , isOrgRepo } from "./context" ;
3
3
import { showFreePlanWarning } from "./config" ;
4
4
import { addComment } from "./github" ;
5
5
import { Config } from "./entities/Config" ;
@@ -12,11 +12,41 @@ export async function hasValidSubscription(app: Probot, ctx: Context<any>, confi
12
12
if ( isFreePaidSubscription ( app , ctx ) ) {
13
13
return true ;
14
14
}
15
+ if ( isOrgRepo ( ctx ) ) {
16
+ const hasPaidPlan = await isCommercialOrganizationPlan ( app , ctx )
17
+ if ( hasPaidPlan ) {
18
+ return true ;
19
+ } else {
20
+ await buyCommercialOrganizationPlanComment ( ctx , config ) ;
21
+ app . log . info ( 'Added comment to buy Commercial organization 🙏 plan' ) ;
22
+ return false ;
23
+ }
24
+ }
15
25
if ( await isPaidPlan ( app , ctx ) ) {
16
26
return true ;
27
+ } else {
28
+ await freePlanWarningComment ( ctx , config ) ;
29
+ return true ;
30
+ }
31
+ }
32
+
33
+ export async function isCommercialOrganizationPlan ( app : Probot , ctx : Context < any > ) {
34
+ try {
35
+ const login = getRepoOwnerLogin ( ctx ) ;
36
+ app . log . info ( `Checking Marketplace for organization: https://github.com/${ login } ...` ) ;
37
+ const id = getRepoOwnerId ( ctx ) ;
38
+ const res = await ctx . octokit . apps . getSubscriptionPlanForAccount ( { account_id : id } ) ;
39
+ const purchase = res . data . marketplace_purchase ;
40
+ if ( purchase . plan && purchase . plan . name === 'Commercial organization' ) {
41
+ app . log . info ( 'Found Commercial organization 💰 plan' ) ;
42
+ return true ;
43
+ } else {
44
+ return false ;
45
+ }
46
+ } catch ( error ) {
47
+ app . log . info ( 'Marketplace purchase not found' ) ;
48
+ return false ;
17
49
}
18
- await displayFreePlanWarning ( ctx , config ) ;
19
- return false ;
20
50
}
21
51
22
52
export async function isPaidPlan ( app : Probot , ctx : Context < any > ) {
@@ -39,7 +69,19 @@ export async function isPaidPlan(app: Probot, ctx: Context<any>) {
39
69
}
40
70
}
41
71
42
- export async function displayFreePlanWarning ( ctx : Context < any > , config : Config ) {
72
+ async function buyCommercialOrganizationPlanComment ( ctx : Context < any > , config : Config ) {
73
+ let buyComment = '' ;
74
+ buyComment += 'Hi there :wave:\n\n' ;
75
+ buyComment += 'Using this App for an organization repository requires a paid ' ;
76
+ buyComment += 'subscription that you can buy on the ' ;
77
+ buyComment += '[GitHub Marketplace](https://github.com/marketplace/create-issue-branch)\n\n' ;
78
+ buyComment += 'If you are a non-profit organization or otherwise can not pay for such a plan, contact me by ' ;
79
+ buyComment += '[creating an issue](https://github.com/robvanderleek/create-issue-branch/issues)' ;
80
+ config . silent = false ;
81
+ await addComment ( ctx , config , buyComment )
82
+ }
83
+
84
+ async function freePlanWarningComment ( ctx : Context < any > , config : Config ) {
43
85
if ( showFreePlanWarning ( config ) ) {
44
86
let freePlanWarning = '' ;
45
87
freePlanWarning += 'Hi there :wave:\n\n' ;
0 commit comments