@@ -63,6 +63,9 @@ func (c *CmdDonate) Run(
63
63
amount := githubv4 .Int (c .Amount )
64
64
isRecurring := githubv4 .Boolean (c .IsRecurring )
65
65
privacyLevel := githubv4 .SponsorshipPrivacy (githubv4 .SponsorshipPrivacyPublic )
66
+ receiveEmails := githubv4 .Boolean (false )
67
+
68
+ sponsorIds := map [string ]string {}
66
69
67
70
// For each recipient create a GH sponsorship that is:
68
71
// - $1
@@ -72,43 +75,74 @@ func (c *CmdDonate) Run(
72
75
row := row
73
76
logger .Infof ("donating %s:%s" , row .SponsorID , row .RecipientID )
74
77
75
- var m struct {
76
- CreateSponsorship struct {
77
- ClientMutationID string
78
- } `graphql:"createSponsorship(input:$input)"`
78
+ failed := false
79
+
80
+ sid , ok := sponsorIds [row .SponsorID ]
81
+ if ! ok {
82
+ var q struct {
83
+ RepositoryOwner struct {
84
+ ID string
85
+ } `graphql:"repositoryOwner(login: $login)"`
86
+ }
87
+ var vars map [string ]any = map [string ]any {
88
+ "login" : githubv4 .String (row .SponsorID ),
89
+ }
90
+
91
+ err := client .Query (ctx , & q , vars )
92
+ if err != nil {
93
+ logger .WithError (err ).Error ("failed to get sponsor id" )
94
+ failed = true
95
+ } else {
96
+ sid = q .RepositoryOwner .ID
97
+ sponsorIds [row .SponsorID ] = sid
98
+ }
79
99
}
80
- id := githubv4 .String (fmt .Sprintf ("%s:%s" , row .SponsorID , row .RecipientID ))
81
- sponsorLogin := githubv4 .String (row .SponsorID )
82
- sponsorableLogin := githubv4 .String (row .RecipientID )
83
- var input githubv4.Input = githubv4.CreateSponsorshipInput {
84
- ClientMutationID : & id ,
85
- IsRecurring : & isRecurring ,
86
- Amount : & amount ,
87
- SponsorLogin : & sponsorLogin ,
88
- SponsorableLogin : & sponsorableLogin ,
89
- PrivacyLevel : & privacyLevel ,
100
+
101
+ if ! failed {
102
+ var m struct {
103
+ CreateSponsorship struct {
104
+ ClientMutationID string
105
+ } `graphql:"createSponsorship(input:$input)"`
106
+ }
107
+ id := githubv4 .String (fmt .Sprintf ("%s:%s" , row .SponsorID , row .RecipientID ))
108
+ sponsorId := githubv4 .ID (sid )
109
+ sponsorableLogin := githubv4 .String (row .RecipientID )
110
+ var input githubv4.Input = githubv4.CreateSponsorshipInput {
111
+ ClientMutationID : & id ,
112
+ IsRecurring : & isRecurring ,
113
+ Amount : & amount ,
114
+ SponsorID : & sponsorId ,
115
+ SponsorableLogin : & sponsorableLogin ,
116
+ PrivacyLevel : & privacyLevel ,
117
+ ReceiveEmails : & receiveEmails ,
118
+ }
119
+
120
+ err := client .Mutate (ctx , & m , input , nil )
121
+ if err != nil {
122
+ logger .WithError (err ).Errorf ("failed to create sponsorship for %s" , row .RecipientID )
123
+ failed = true
124
+ }
90
125
}
91
126
92
- err := client .Mutate (ctx , & m , input , nil )
93
- if err != nil {
94
- logger .WithError (err ).Error ("failed to create sponsorship" )
127
+ if failed {
95
128
/* autoquery name: UpdateDonationDonateAttemptTs :exec
96
129
97
130
UPDATE donations
98
131
SET donate_attempt_ts = UNIXEPOCH()
99
132
WHERE id = ?;
100
133
*/
101
134
_ = db .UpdateDonationDonateAttemptTs (ctx , row .ID )
102
- continue
103
- }
104
135
105
- /* autoquery name: UpdateDonationDonateTs :exec
136
+ } else {
106
137
107
- UPDATE donations
108
- SET donate_ts = UNIXEPOCH()
109
- WHERE id = ?;
110
- */
111
- _ = db .UpdateDonationDonateTs (ctx , row .ID )
138
+ /* autoquery name: UpdateDonationDonateTs :exec
139
+
140
+ UPDATE donations
141
+ SET donate_ts = UNIXEPOCH()
142
+ WHERE id = ?;
143
+ */
144
+ _ = db .UpdateDonationDonateTs (ctx , row .ID )
145
+ }
112
146
}
113
147
114
148
return nil
0 commit comments