Skip to content

Instantly share code, notes, and snippets.

@richardm-stripe
Last active January 23, 2020 22:37
Show Gist options
  • Save richardm-stripe/2c335c99b08f819b66e9c649695c9b8c to your computer and use it in GitHub Desktop.
Save richardm-stripe/2c335c99b08f819b66e9c649695c9b8c to your computer and use it in GitHub Desktop.
Parse php codegen diff
const parser = require("git-diff-parser");
const main = async () => {
const data = await new Promise((resolve, reject) => {
let data = "";
process.stdin.on("data", d => (data += d.toString()));
process.stdin.on("end", () => {
return resolve(data);
});
});
const parsed = parser(data);
const propertyChanges = parsed.commits[0].files
.map(f => {
return f.lines.map(line => ({ ...line, filename: f.name }));
})
.reduce((acc, cur) => [...acc, ...cur], [])
.filter(l => l.type !== "normal")
.filter(l => l.text.indexOf("property") !== -1)
.map(parsePropertyChange);
collectChanges(propertyChanges).forEach(x => console.log(x));
};
const parsePropertyChange = line => {
const [empty, asterisk, property, type, propertyName] = line.text.split(" ");
return {
name: `${line.filename}${propertyName}`,
diff: line.type,
type,
filename: line.filename,
propertyName
};
};
const collectChanges = changes => {
const adds = {};
const deletes = {};
changes.forEach(({ name, diff, type }) => {
if (diff === "added") {
adds[name] = type;
}
if (diff === "deleted") {
deletes[name] = type;
}
});
return changes
.map(({ name, diff, type }) => {
if (adds[name] && deletes[name]) {
if (diff === "added") {
return `Type change: ${name} (${deletes[name]} -> ${adds[name]})`;
}
return;
}
if (adds[name]) {
return `Add property: ${name} ${adds[name]}`;
}
if (deletes[name]) {
return `Remove property: ${name} ${deletes[name]}`;
}
throw new Error("wtf");
})
.filter(Boolean);
};
main()
.then(() => process.exit(0))
.catch(e => console.error(e) || process.exit(1));

Added properties

lib/Checkout/Session.php$metadata \Stripe\StripeObject|null
lib/CreditNote.php$discount_amount int
lib/CreditNote.php$lines \Stripe\Collection
lib/CreditNote.php$out_of_band_amount int|null
lib/CreditNote.php$subtotal int
lib/CreditNote.php$tax_amounts \Stripe\StripeObject[]
lib/CreditNote.php$total int
lib/Invoice.php$tax_percent float|null
lib/InvoiceItem.php$unified_proration bool
lib/Subscription.php$pending_update \Stripe\StripeObject|null
lib/SubscriptionSchedule.php$default_settings \Stripe\StripeObject

Removed properties

lib/EphemeralKey.php$associated_objects array
lib/SubscriptionSchedule.php$billing_thresholds mixed|null
lib/SubscriptionSchedule.php$collection_method string|null
lib/SubscriptionSchedule.php$default_payment_method string|null
lib/SubscriptionSchedule.php$invoice_settings mixed|null

Properties whose type has changed

lib/Account.php$business_profile (mixed|null -> \Stripe\StripeObject|null)
lib/Account.php$capabilities (mixed -> \Stripe\StripeObject)
lib/Account.php$company (mixed -> \Stripe\StripeObject)
lib/Account.php$individual (mixed -> \Stripe\Person)
lib/Account.php$requirements (mixed -> \Stripe\StripeObject)
lib/Account.php$settings (mixed|null -> \Stripe\StripeObject|null)
lib/Account.php$tos_acceptance (mixed -> \Stripe\StripeObject)

lib/Balance.php$available (array -> \Stripe\StripeObject[])
lib/Balance.php$connect_reserved (array -> \Stripe\StripeObject[])
lib/Balance.php$pending (array -> \Stripe\StripeObject[])

lib/BalanceTransaction.php$fee_details (mixed -> \Stripe\StripeObject[])

lib/BitcoinReceiver.php$transactions (mixed -> \Stripe\Collection)

lib/Charge.php$billing_details (mixed -> \Stripe\StripeObject)
lib/Charge.php$fraud_details (mixed|null -> \Stripe\StripeObject|null)
lib/Charge.php$outcome (mixed|null -> \Stripe\StripeObject|null)
lib/Charge.php$payment_method_details (mixed|null -> \Stripe\StripeObject|null)
lib/Charge.php$shipping (mixed|null -> \Stripe\StripeObject|null)
lib/Charge.php$source (mixed|null -> \Stripe\StripeObject|null)
lib/Charge.php$transfer_data (mixed|null -> \Stripe\StripeObject|null)
lib/Checkout/Session.php$display_items (mixed|null -> \Stripe\StripeObject[]|null)

lib/CountrySpec.php$verification_fields (mixed -> \Stripe\StripeObject)

lib/Customer.php$address (mixed|null -> \Stripe\StripeObject|null)
lib/Customer.php$invoice_settings (mixed -> \Stripe\StripeObject)
lib/Customer.php$shipping (mixed|null -> \Stripe\StripeObject|null)

lib/Dispute.php$balance_transactions (BalanceTransaction[] -> \Stripe\BalanceTransaction[])
lib/Dispute.php$evidence (mixed -> \Stripe\StripeObject)
lib/Dispute.php$evidence_details (mixed -> \Stripe\StripeObject)

lib/Event.php$data (mixed -> \Stripe\StripeObject)
lib/Event.php$request (mixed|null -> \Stripe\StripeObject|null)

lib/Invoice.php$custom_fields (array|null -> \Stripe\StripeObject[]|null)
lib/Invoice.php$customer_address (mixed|null -> \Stripe\StripeObject|null)
lib/Invoice.php$customer_shipping (mixed|null -> \Stripe\StripeObject|null)
lib/Invoice.php$customer_tax_ids (array|null -> \Stripe\StripeObject[]|null)
lib/Invoice.php$default_tax_rates (array|null -> \Stripe\TaxRate[]|null)
lib/Invoice.php$status_transitions (mixed -> \Stripe\StripeObject)
lib/Invoice.php$threshold_reason (mixed -> \Stripe\StripeObject)
lib/Invoice.php$total_tax_amounts (array|null -> \Stripe\StripeObject[]|null)

lib/InvoiceItem.php$period (mixed -> \Stripe\StripeObject)
lib/InvoiceItem.php$tax_rates (array|null -> \Stripe\TaxRate[]|null)

lib/Issuing/Authorization.php$balance_transactions (\Stripe\Collection -> \Stripe\BalanceTransaction[])
lib/Issuing/Authorization.php$card (Card -> \Stripe\Card)
lib/Issuing/Authorization.php$merchant_data (mixed -> \Stripe\StripeObject)
lib/Issuing/Authorization.php$request_history (mixed -> \Stripe\StripeObject[])
lib/Issuing/Authorization.php$transactions (array -> \Stripe\Issuing\Transaction[])
lib/Issuing/Authorization.php$verification_data (mixed -> \Stripe\StripeObject)

lib/Issuing/Card.php$authorization_controls (mixed -> \Stripe\StripeObject)
lib/Issuing/Card.php$pin (mixed|null -> \Stripe\StripeObject|null)
lib/Issuing/Card.php$shipping (mixed|null -> \Stripe\StripeObject|null)

lib/Issuing/Cardholder.php$authorization_controls (mixed|null -> \Stripe\StripeObject|null)
lib/Issuing/Cardholder.php$billing (mixed -> \Stripe\StripeObject)
lib/Issuing/Cardholder.php$requirements (mixed -> \Stripe\StripeObject)

lib/Issuing/Dispute.php$evidence (mixed -> \Stripe\StripeObject)

lib/Issuing/Transaction.php$merchant_data (mixed -> \Stripe\StripeObject)

lib/Mandate.php$customer_acceptance (mixed -> \Stripe\StripeObject)
lib/Mandate.php$multi_use (mixed|null -> \Stripe\StripeObject)
lib/Mandate.php$payment_method_details (mixed -> \Stripe\StripeObject)
lib/Mandate.php$single_use (mixed|null -> \Stripe\StripeObject)

lib/Order.php$items (OrderItem[] -> \Stripe\OrderItem[])
lib/Order.php$shipping (mixed|null -> \Stripe\StripeObject|null)
lib/Order.php$shipping_methods (array|null -> \Stripe\StripeObject[]|null)
lib/Order.php$status_transitions (mixed|null -> \Stripe\StripeObject|null)

lib/OrderReturn.php$items (OrderItem[] -> \Stripe\OrderItem[])

lib/PaymentIntent.php$last_payment_error (mixed|null -> \Stripe\StripeObject|null)
lib/PaymentIntent.php$next_action (mixed|null -> \Stripe\StripeObject|null)
lib/PaymentIntent.php$payment_method_options (mixed|null -> \Stripe\StripeObject|null)
lib/PaymentIntent.php$shipping (mixed|null -> \Stripe\StripeObject|null)
lib/PaymentIntent.php$transfer_data (mixed|null -> \Stripe\StripeObject|null)
lib/PaymentMethod.php$au_becs_debit (mixed|null -> \Stripe\StripeObject)
lib/PaymentMethod.php$billing_details (mixed -> \Stripe\StripeObject)
lib/PaymentMethod.php$card (mixed -> \Stripe\Card)
lib/PaymentMethod.php$card_present (mixed -> \Stripe\StripeObject)
lib/PaymentMethod.php$ideal (mixed|null -> \Stripe\StripeObject)
lib/PaymentMethod.php$sepa_debit (mixed|null -> \Stripe\StripeObject)

lib/Plan.php$tiers (mixed|null -> \Stripe\StripeObject[]|null)
lib/Plan.php$transform_usage (mixed|null -> \Stripe\StripeObject|null)

lib/Product.php$active (bool|null -> bool)
lib/Product.php$package_dimensions (mixed|null -> \Stripe\StripeObject|null)

lib/Recipient.php$active_account (mixed|null -> \Stripe\BankAccount|null)
lib/Reporting/ReportRun.php$parameters (mixed -> \Stripe\StripeObject)
lib/Reporting/ReportRun.php$result (mixed|null -> \Stripe\File|null)

lib/Review.php$ip_address_location (mixed|null -> \Stripe\Terminal\Location|null)
lib/Review.php$session (mixed|null -> \Stripe\Checkout\Session|null)

lib/SKU.php$inventory (mixed -> \Stripe\StripeObject)
lib/SKU.php$package_dimensions (mixed|null -> \Stripe\StripeObject|null)

lib/SetupIntent.php$last_setup_error (mixed|null -> \Stripe\StripeObject|null)
lib/SetupIntent.php$next_action (mixed|null -> \Stripe\StripeObject|null)
lib/SetupIntent.php$payment_method_options (mixed|null -> \Stripe\StripeObject|null)

lib/Sigma/ScheduledQueryRun.php$error (mixed -> \Stripe\StripeObject)

lib/Source.php$ach_credit_transfer (mixed -> \Stripe\StripeObject)
lib/Source.php$ach_debit (mixed -> \Stripe\StripeObject)
lib/Source.php$acss_debit (mixed -> \Stripe\StripeObject)
lib/Source.php$alipay (mixed -> \Stripe\StripeObject)
lib/Source.php$au_becs_debit (mixed -> \Stripe\StripeObject)
lib/Source.php$bancontact (mixed -> \Stripe\StripeObject)
lib/Source.php$card (mixed -> \Stripe\Card)
lib/Source.php$card_present (mixed -> \Stripe\StripeObject)
lib/Source.php$code_verification (mixed -> \Stripe\StripeObject)
lib/Source.php$eps (mixed -> \Stripe\StripeObject)
lib/Source.php$giropay (mixed -> \Stripe\StripeObject)
lib/Source.php$ideal (mixed -> \Stripe\StripeObject)
lib/Source.php$klarna (mixed -> \Stripe\StripeObject)
lib/Source.php$multibanco (mixed -> \Stripe\StripeObject)
lib/Source.php$owner (mixed|null -> \Stripe\StripeObject|null)
lib/Source.php$p24 (mixed -> \Stripe\StripeObject)
lib/Source.php$receiver (mixed -> \Stripe\StripeObject)
lib/Source.php$redirect (mixed -> \Stripe\StripeObject)
lib/Source.php$sepa_credit_transfer (mixed -> \Stripe\StripeObject)
lib/Source.php$sepa_debit (mixed -> \Stripe\StripeObject)
lib/Source.php$sofort (mixed -> \Stripe\StripeObject)
lib/Source.php$source_order (mixed -> \Stripe\Order)
lib/Source.php$three_d_secure (mixed -> \Stripe\ThreeDSecure)
lib/Source.php$wechat (mixed -> \Stripe\StripeObject)

lib/Subscription.php$billing_thresholds (mixed|null -> \Stripe\StripeObject|null)
lib/Subscription.php$default_tax_rates (array|null -> \Stripe\TaxRate[]|null)
lib/Subscription.php$pending_invoice_item_interval (mixed|null -> \Stripe\StripeObject|null)

lib/SubscriptionItem.php$billing_thresholds (mixed|null -> \Stripe\StripeObject|null)
lib/SubscriptionItem.php$tax_rates (array|null -> \Stripe\TaxRate[]|null)

lib/SubscriptionSchedule.php$current_phase (mixed|null -> \Stripe\StripeObject|null)
lib/SubscriptionSchedule.php$phases (mixed -> \Stripe\StripeObject[])
lib/SubscriptionSchedule.php$renewal_interval (mixed|null -> \Stripe\StripeObject|null)

lib/Terminal/Location.php$address (mixed -> \Stripe\StripeObject)

lib/ThreeDSecure.php$card (mixed -> \Stripe\Card)

lib/Topup.php$source (mixed -> \Stripe\Source)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment