<commit_before>package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strings"
)

func main() {
	if len(os.Args) != 2 {
		fmt.Printf("USAGE: %v VERSION\n", os.Args[0])
		os.Exit(1)
	}

	version := os.Args[1]
	if err := run(version, os.Stdout); err != nil {
		log.Fatal(err)
	}
}

const (
	searching = iota
	foundHeader
	printing
)

func run(version string, out io.Writer) error {
	if version[0] == 'v' {
		version = version[1:]
	}

	file, err := os.OpenFile("CHANGELOG.md", os.O_RDONLY, 0444)
	if err != nil {
		return err
	}
	defer file.Close()

	state := searching
	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		line := scanner.Text()

		switch state {
		case searching:
			if line == "# "+version {
				state = foundHeader
			}
		case foundHeader:
			if line == "" {
				continue
			}
			state = printing
			fallthrough
		case printing:
			if strings.HasPrefix(line, "# ") {
				// next version section
				return nil
			}
			fmt.Fprintln(out, line)
		default:
			return fmt.Errorf("unexpected state %v on line %q", state, line)
		}

	}

	if err := scanner.Err(); err != nil {
		return err
	}

	if state < printing {
		return fmt.Errorf("could not find version %q in changelog", version)<commit_msg>Fix release script to handle dates in changelogs (#218)<commit_after>package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strings"
)

func main() {
	if len(os.Args) != 2 {
		fmt.Printf("USAGE: %v VERSION\n", os.Args[0])
		os.Exit(1)
	}

	version := os.Args[1]
	if err := run(version, os.Stdout); err != nil {
		log.Fatal(err)
	}
}

const (
	searching = iota
	foundHeader
	printing
)

func run(version string, out io.Writer) error {
	if version[0] == 'v' {
		version = version[1:]
	}

	file, err := os.OpenFile("CHANGELOG.md", os.O_RDONLY, 0444)
	if err != nil {
		return err
	}
	defer file.Close()

	state := searching
	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		line := scanner.Text()

		switch state {
		case searching:
			if strings.HasPrefix(line, "# "+version+" (") {
				state = foundHeader
			}
		case foundHeader:
			if line == "" {
				continue
			}
			state = printing
			fallthrough
		case printing:
			if strings.HasPrefix(line, "# ") {
				// next version section
				return nil
			}
			fmt.Fprintln(out, line)
		default:
			return fmt.Errorf("unexpected state %v on line %q", state, line)
		}

	}

	if err := scanner.Err(); err != nil {
		return err
	}

	if state < printing {
		return fmt.Errorf("could not find version %q in changelog", version)
{'fraction_non_alphanumeric': 0.1498800959232614, 'fraction_numerical': 0.009192645883293365, 'mean_word_length': 3.011217948717949, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4305210', 'n_tokens_mistral': 1060, 'n_tokens_neox': 938, 'n_words': 249}